For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > December 2006 > Re: [SMARTY] Using assign within a function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] Using assign within a function
Ken Snyder

2006-12-11, 7:20 pm

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}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com