[ZPT] Re: Add 'parity' to repeat?
Evan Simpson
evan at 4-am.com
Wed Aug 27 12:35:21 EDT 2003
Charlie Clark wrote:
> <table tal:define="classes python:{'1':'red', '2':'green', '3':'blue'}">
> <tr tal:attributes="class python:classes[string(repeat.row.number)]"></tr>
> </table>
>
> At least I think that should work: it adds power but maintains clarity.
Another usable idiom is indexing:
<table tal:define="classes python:('one', 'two', 'three')">
<tr tal:define="i repeat/row/index"
tal:attributes="class python:classes[i % 3]">
At least in Plone, though, simple even/odd alternation is *everywhere*.
> By the way thanx very much for your private explanation of namespaces.
> TALES blocks then are like Python functions?
A bit, but mostly they're like themselves. The best way I can find to
think about ZPT variable scoping is to refer to the actual
implementation -- a stack of dictionaries with the globals dictionary on
the bottom. Every tal:define builds a dictionary of local variable
definitions and pushes it onto the stack, from which it is popped at the
end of the element. Global variable definitions mutate the globals
dictionary directly. Every variable lookup travels down the stack, with
the effect that locals override globals and "more local" locals override
"less local" locals.
Cheers,
Evan @ 4-am
More information about the ZPT
mailing list