Re: [SMARTY] Sub Total in smarty
| From: | Jason Hubble | Date: | Fri, 28 Nov 2003 22:42:11 +0000 |
| Subject: | Re: [SMARTY] Sub Total in smarty | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-10603@lists.php.net to get a copy of this message | ||
A good way of structuring the array you send to smarty would be like this:
$info['items'][] =
array('name'=>'CD-ROM','price'=>'32.50');
$info['items'][] =
array('name'=>'Floppy','price'=>'15.00');
$info['total'] = 47.50;
$smarty->assign("price",$info);
In other words, send the price to the template. Don't rely on the template
to add up the total, much less the CORRECT PRICE of the total :-).
> {section name=i loop=$price}
> <hr>
> {$price[i].name} {$price[i].price}
> <hr>
> {/section}
you would rewrite this to:
{section name=i loop=$price.items}
<hr>
{$price.items[i].name} {$price.items[i].price}
<hr>
{/section}
Total: {$price.total}
"dr. zoidberg" <php@1203.qwe.uni.cc> wrote:
> Hello,
>
> I have
>
> {section name=i loop=$price}
> <hr>
> {$price[i].name} {$price[i].price}
> <hr>
> {/section}
>
> I lope through names and prices of some hardware, and I want to display
> total cost of all components. I dont know how to do that :( any help is
> appreciated.
>
> TNX