Comunitatea PHP Romania
 

 
{eval}

{eval}

{eval} is used to evaluate a variable as a template. This can be used for things like embedding template tags/variables into variables or tags/variables into config file variables.

If you supply the assign attribute, the output of the {eval} function will be assigned to this template variable instead of being output to the template.

Attribute NameTypeRequiredDefaultDescription
varmixedYesn/aVariable (or string) to evaluate
assignstringNon/aThe template variable the output will be assigned to

Technical Note:

  • Evaluated variables are treated the same as templates. They follow the same escapement and security features just as if they were templates.

  • Evaluated variables are compiled on every invocation, the compiled versions are not saved! However if you have caching enabled, the output will be cached with the rest of the template.

Example 8-6. {eval}

The contents of the config file, setup.conf.

emphstart = <strong>
emphend = </strong>
title = Welcome to {$company}'s home page!
ErrorCity = You must supply a {#emphstart#}city{#emphend#}.
ErrorState = You must supply a {#emphstart#}state{#emphend#}.

Where the template is:

{config_load file='setup.conf'}

{eval var=$foo}
{eval var=#title#}
{eval var=#ErrorCity#}
{eval var=#ErrorState# assign='state_error'}
{$state_error}

The above template will output:

This is the contents of foo.
Welcome to Foobar Pub & Grill's home page!
You must supply a <strong>city</strong>.
You must supply a <strong>state</strong>.

Example 8-7. Another {eval} example

This outputs the server name (in uppercase) and IP. The assigned variable $str could be from a database query.

<?php
$str 
'The server name is {$smarty.server.SERVER_NAME|upper} '
       
.'at {$smarty.server.SERVER_ADDR}';
$smarty->assign('foo',$str);
?>

Where the template is:

{eval var=$foo}

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
acasa , in pat
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Loans | Libros | Loans | Unsecured Loans | Loans
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis