Re: [SMARTY] section sum of numbers...

From: Date: Thu, 21 Jul 2005 00:13:10 +0000
Subject: Re: [SMARTY] section sum of numbers...
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12818@lists.php.net to get a copy of this message
messju mohr wrote:
On Wed, Jul 20, 2005 at 01:54:15PM -0500, Andras Kende wrote:
Hello, Is there a way to find out the SUM of the numbers from the template ?
it's possible to do this with {assign} and {math}, but it's recommended to do this kind of logic from php and just assign the result.
now I can't remember whether the lastest version of Smarty allows foreach Iterator overloading on objects yet (still running a small hack locally) but this is a nice example of why I would like to see more OO capability. assume it was a forach loop (I never use section, always seems awkward somehow): ------------->8------------- <table> {foreach name=i from=$items item=item} <tr> <td>{$item->name}</td> <td>{$item->price}</td> </tr> {/foreach} </table> There items: {$items->basketCount()} {* takes quantities into account *}
Total price: {$items->getTotal()}    {* sums everything, discount aware *}
------------->8------------- note $items is an object. :-) rgds, Jochem
------------- {section name=i loop=$items} <tr> <td>{$items[i].name}</td> <td>{$items[i].price}</td> </tr> {/section} There items: {$smarty.section.i.total} Total price: {$smarty ??? } ------------- <tr> <td>Joe</td> <td>2.00</td> </tr> <tr> <td>Steve</td> <td>5.00</td> </tr> There items: 2 Total price: 7.00 ------------- Thanks, Andras Kende http://www.kende.com/ -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


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