[ZPT] Add 'parity' to repeat?

Evan Simpson evan at 4-am.com
Tue Aug 26 13:00:41 EDT 2003


Charlie Clark wrote:
> python: test (repeat.thing.number % n == 0, 1, 0)

The 'test()' is unnecessary -- "python:repeat.thing.number % n == 0" 
should give the same result.

> PS. Could someone please explain to me why the following doesn't work as I 
> expected it to.
> 
> <div tal:define="count python: 0">
> <tr tal:define="count python: count + 1!

This can work if you stick a 'global' in each tal:define.  Local 
definitions (the default) only apply within their statement element, and 
upon exiting the element, the variable reverts to the value (if any) it 
had on entry.  In this case, the value is always zero when the 'tr' is 
entered, one within the 'tr', and goes back to zero at the '</tr>'. 
Global variables keep whatever value you give them for the entire 
rendering of the template, although they can be hidden/overridden by a 
local definition of the same name.

Cheers,

Evan @ 4-am




More information about the ZPT mailing list