eval function
eval function
If the special attribute "assign" is specified, the output value of the function will be assigned to the template variable specified by assign instead of being output directly. .
Technical Note: Variables to be evaluated are treated as templates. They follow the same structure and safety features as templates.
Technical points: The variables to be evaluated are recompiled each time they are called, and the compiled version is not saved! But when the buffering setting is turned on, the output will be buffered by other templates.
test.php:
##$smarty->assign('data',array(1,2,3));
{section name=rows loop=$data}
<tr class="{cycle values="odd,even"}"> <td>{$data[rows]}</td> ;
</tr>
{/section}
##Output:
<tr class="odd" > <td>1</td></tr>
<tr class="even">
<td>2</td>
</tr>
<tr class="odd">
<td>3</td>
</tr>