Re: [SMARTY] Using assign within a function

From: Date: Thu, 07 Dec 2006 17:53:03 +0000
Subject: Re: [SMARTY] Using assign within a function
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13634@lists.php.net to get a copy of this message
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}

« previous php.smarty.general (#13634) next »