November 27, 2012

ZPT Power Tip!

For a long time there was a test() method available in ZPT:

<td tal:attributes="class python: test(some_condition, 'even', 'odd')"%>

With the move to browser views the test() had gone and you had to write something like

<td tal:attributes="class python: some_condition and 'even' or 'odd')">

as a replacement. This notation may have side-effects in some rare cases.

Now with Python 2.6 or higher you can rewrite your code the following way

<td tal:attributes="class python: 'even' if some_condition else 'odd')">

in a more clean way. In addition this notation is free of side-effects.