Re: [SMARTY] dynamic inserts
| From: | M Mohr | Date: | Thu, 12 Dec 2002 12:17:40 +0000 |
| Subject: | Re: [SMARTY] dynamic inserts | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6751@lists.php.net to get a copy of this message | ||
On Wed, Dec 11, 2002 at 03:48:45PM -0500, paul@dostuff.net wrote:
> Hello,
>
> This question has been asked before, but I did not find a satisfactory
> workaround or explanation and now I'm hoping that will change. Basically
> what I want to do is insert something using a variable, like this:
>
> {insert name=$var}
>
> Is this possible? What I am attempting to do is load boxes of dynamic
> content onto a cached page. Different pages have different boxes. I want
> to assign what boxes should be on each page in the following way:
>
> $box = array();
> $box[] = "poll";
> $box[] = "login";
> $smarty->assign("box",$box);
>
> And whatnot. Then the template will load through each variable in the
> array like this:
>
> {foreach key=key item=value name=loop from=$box}
> {insert name=$value}
> {/foreach}
>
> Shouldn't this theoretically work? What am I doing wrong.
maybe it should. it doesen't, but smarty would try to cache the
foreach-loop around your inserts, which is maybe not what you want
anyway.
what about moving the foreach inside your insert-function??
for example (not testet, but should show what i mean):
function insert_box($params, &$smarty) {
foreach ($params['box'] as $box) {
$fun = 'insert_'.$box;
$fun($params, &$smarty);
}
}
which is called as
{insert name=box box=$box}
of course you should not try to add a $box[] = 'box' to your array, since
you would have built an endless recursion. :)
have fun
messju
> ~Paul