[ZPT] Add 'parity' to repeat?
Charlie Clark
charlie at begeistert.org
Tue Aug 26 18:50:11 EDT 2003
On 2003-08-25 at 20:52:47 [+0200], Evan Simpson wrote:
> The use of "python:test(path('repeat/thing/odd'), 'odd', 'even')" and
> variants has become so common as to merit its own method.
>
> I suggest that 'parity()' be added to the stock repeat object. It would
> return the string "odd" or "even", depending on the repetition index.
>
> This would allow the nicely concise:
>
> <tr tal:attributes="class repeat/row/parity">
>
> An alternate approach would be to create a subpath prefix that has a
> 'parity' method, perhaps along with all of the other repetition methods
> that are computed directly from 'index', such as 'roman' and 'odd'. Then
> we could write "repeat/row/index/int:parity", for example. Of course,
> this depends on the inclusion of subpath prefixes into a release.
>
> Thoughts?
I'm not sure about this: alternating row colours aren't the only thing it's
useful to be able to know which number row you're on: I recently
implemented a conditional "top" anchor for a list of definitions which only
showed every nth item to avoid screen clutter so I was actually using
python: test (repeat.thing.number % n == 0, 1, 0). While it might be nice
to have this more easily available my biggest problem was actually
remembering that repeat..number actually exists and how to use it and this
was only because all my attempts to set up a local variable failed
miserably (ZPT namespaces don't work like Python ones) and I was forced
back to the documentation to see if there was anything special. My point
being this: it was more logical and easier to remember for me to apply a
generic mathematical function rather than use a little bit of magic. I
don't know how often this happens to others more deeply steeped in ZPT or
simply less forgetful ;-) but worth bearing in mind, I hope.
Charlie
PS. Could someone please explain to me why the following doesn't work as I
expected it to.
<div tal:define="count python: 0;
results=here/someMethod">
<tr tal:define="count python: count + 1!
tal:repeat="result results">
<td tal:content="count"></td>
</tr>
</div>
More information about the ZPT
mailing list