[ZPT] Generating tables in Page Templates

Eron Lloyd elloyd at lancaster.lib.pa.us
Thu May 8 00:16:20 EDT 2003


Hello!

I've been porting a site from DTML to ZPT, and all seems to be going well (ZPT 
is awesome!), until I reached a page that requires the generated table to 
display results in two-column tables, with a new item in each cell (not a 
related pair). In DTML, this was very easy, as it wasn't validating the HTML 
markup. I'd just hack up the table's <tr> and </tr> tags. ZPT however, is not 
happy when you try and sneak in a conditional <tr> or </tr> tag. I'm sure 
several people have come across this challenge before, but I have yet to see 
anything in the mailing list (I'm still going through the archives).

A simple example:

<table tal:define="seq python:range(4)" border="1">
<tr tal:repeat="item seq">
    <td tal:content="item">Will display a number from 0 to 3.</td>
</tr>
</span>
</table>

*producing something like*

<table border="1">
<tr>
    <td>0</td>
    <td>1</td>
</tr>
<tr>
    <td>2</td>
    <td>3</td>
</tr>
</table>

*instead of*

<table border="1">
<tr>
    <td>0</td>
</tr>
<tr>
    <td>1</td>
</tr>
<tr>
    <td>2</td>
</tr>
<td>
    <td>3</td>
</tr>
</table>

I can't think of a logical way to break up the table to have it produce rows 
two by two. Attempting to wrap the <tr> tags with, for example a <span 
tal:condition="repeat/item/odd"></span> pair breaks the nesting rules, and 
</tr> tags (obviously) cannot contain attributes. If anyone can figure this 
out, I'll add a section to the Zope Book in Advanced Page Templates with the 
solution.

Truly stumped on such a basic problem,

Eron



More information about the ZPT mailing list