Re: [SMARTY] Using assign within a function
[email protected] (Ken Snyder) Thu, 07 Dec 2006 10:53:03 -0700
| Newsgroups | php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
Donald Organ wrote:
> is it possible to have something like this, inside a template?
>
> {foreach from=$Items item=Item}
> {php}
> $thumb = $product->getImageThumb();
> $smarty->assign( 'ProdThumb', $thumb );
> {/php}
> {$ProdThumb}
> {/foreach}
>
You can do:
{foreach from=$Items item=Item}
{assign var=ProdThum value=$product->getImageThumb($Item)}
{$ProdThumb}
{/foreach}
However, it is generally better to restrict templates to only performing
presentation operations. I would recommend getting the thumbnail list
beforehand:
{foreach from=$ThumbnailList item=ThumbSrc}
<img src="{$ThumbSrc}" height="100" width="100" alt="" />
{/foreach}
Or
{foreach from=$Products item=Product}
<img src="{$Product.ThumbSrc}" height="100" width="100"
alt="{$Product.AltText} title="{$Product.Description}" />
{/foreach}