What is the strategy in smarty for using different variables each time a template is included in another template?
Here is what I mean. I have a smarty template that creates a simple navigation list.
<ul class='linkList'>
<li>
<h3>{$title}</h3>
<ul>
{foreach $links as $d}
<li><a title='{$d...}' href='{$d....}'>{$d.text}</a></li>
{/foreach}
</ul>
</开发者_开发技巧li>
</ul>
I want to include it a number of times in my main template and each time pass it different values. Im not sure what strategy to use to do this.
If I assign variables in my php file like this
$smarty->assign('links',array(.....);
$smarty->assign('title','My first link list');
$smarty->assign('links',array(different values);
$smarty->assign('title','My second link list');
and then include the template twice i will just get the same list twice with the second lot of values.
The {include}
tag allows you to pass variables in the call:
{include 'linklist.tpl' title="Sample Links 1" links=$link_array1}
{include 'linklist.tpl' title="Sample Links 2" links=$link_array2}
Otherwise, I'm pretty sure you can use either {assign}
or the short form of assign ({$var=value}
) before including the template.
精彩评论