[ZDP] BackTalk to Document The Zope Book (2.5 Edition)/Advanced Page Templates
webmaster@zope.org
webmaster@zope.org
Mon, 07 Oct 2002 03:37:28 -0400
A comment to the paragraph below was recently added via http://www.zope.org/Documentation/Books/ZopeBook/current/AdvZPT.stx#4-138
---------------
The 'test' function works like an if/then/else statement. See
Appendix A, "DTML Reference" for more information on the
'test' function. Here's another example of how you can use the
'test' function::
<tr tal:define="oddrow repeat/item/odd"
tal:attributes="class python:test(oddrow, 'oddclass',
'evenclass')">
% Anonymous User - Apr. 18, 2002 12:43 pm:
It's easy to understand the objective, but the example is cryptic, could you
add a bit of code?
% Anonymous User - June 11, 2002 3:07 am:
My problem with this is that i use the <tr> tag for tal:repeat, and it doesn't seem to recognise the
repeat/item/* within the same <tr> tag context. If you don't use the <tr> to repeat rows of a table, what do
you use? Every other tag is technically illegal inside a table, but outside <tr> tags. I know that the
rendered html won't show them if you use omit-tag, or whatever, but it seems a crappy solution to build
invalid html wrappers, when the point of page templates is to be 100% valid HTML. So the only option i can
find is to put that clunky code into every <td> tag within the <tr>... which is ugly, and also slow. So it
seems the duplicate <tr> is the only method I can see which one can alternate classes, and maintain valid
HTML in their zpt files.
% Anonymous User - July 17, 2002 6:34 am:
An complete example would be:
<table>
<tr tal:attributes="class python:test(path('repeat/item/odd','odd','even')"
tal:repeat="item container/objectValues">
<td tal:content="item/title_or_id">Some title</td>
</tr>
</table>
with eg as CSS:
.even { background-color: gray; }
.odd { background-color: yellow; }
It gets ride of the 'tal:define'. The usage of 'path()' is explained in the next section.
% Anonymous User - July 18, 2002 8:31 am:
<tr tal:attributes="class python:test(path('repeat/item/odd','odd','even')"
^ ^
should be
<tr tal:attributes="class python:path(test('repeat/item/odd','odd','even')"
% Anonymous User - July 20, 2002 7:05 am:
i think we're still missing a closing bracket...
% Anonymous User - Oct. 7, 2002 3:37 am:
actually the first line of the first line should look like this:
<tr tal:attributes="class python:path(test(path('repeat/item/odd'),'string:odd','string:even'))"
but as i don't drink that much i feel betta with this:
<tr tal:attributes="class python:test(repeat['item'].odd(),'odd','even')"
or, when code might be read by others, this:
<table>
<tr tal:attributes="class python:repeat['item'].odd() and 'odd' or 'even'"
tal:repeat="item container/objectValues">
<td tal:content="item/title_or_id">Some title</td>
</tr>
</table>