<tal:qty define="global total_quantity python: 0;" /> <table> <thead> <th>Item</th> <th>Quantity</th> </thead> <tbody> <tr tal:repeat="item results"> <td tal:content="item/item"></td> <td tal:content="item/quantity" tal:define="global total_quantity python: total_quantity + item['quantity']"> </td> </tr> </tbody> </table> <dl> <dt>Total Items</dt> <dd tal:content="total_quantity" /> </dl>
Zope ZPT Using global variables to track totals
This is ideally done in a python script, but for very simple cases, as seen here, it is acceptable.
Snippet Viewed 1584 times.
Share your Zope ZPT code snippets:
- Get some recognition & a link back to your site.
- Create your own code library.
- Help your fellow developers, as they have helped you.