[ZPT] Conditional closing </tr> tag for TAL

Tino Wildenhain tino at wildenhain.de
Mon Jun 20 12:42:34 EDT 2005


Am Montag, den 20.06.2005, 08:59 -0700 schrieb Takahashi, Michael:
> Hi Guys,
> 
>  
> 
> I’m developing a dynamic ZPT that builds a table dynamically from an
> external database. I’d like to create a table row with at most two
> columns.  The condition is that if there is an odd number of data, the
> last table row will only contain one <td>.  If there is an even number
> of data, then the last table row will contain two <td>’s.  Sounds
> pretty simple right?  Just create a condition on the closing </tr>

This makes no sense. You could end up with invalid HTML and thats
what ZPT avoids.

>  tag….well as I have found out, it’s not so simple in TAL.
> 
> For example:
> 4 items of data will create two table rows
> 
> <tr>
>   <td></td>
>   <td></td>
> </tr>
> 
> <tr>
>   <td></td>
>   <td></td>
> </tr>
> 
> 5 items of data will create 3 table rows
> <tr>
>    <td></td>
>    <td></td>
> </tr>
> <tr>
>    <td></td>
>    <td></td>
> </tr>
> <tr>
>    <td></td>
> </tr>

Thats valid HTML but ugly - better you avoid empty cells or use
colspan.

Why not prepare your data as lists of lists and go like this:

<tr tal:repeat="row here/datafunction">
  <td tal:repeat="column row" tal:content="column">Sample</td>
</tr>

ready.

(You can also use lists of dicts if you want more data per
row for example background color alternation if your client
does not properly support the CSS way to do so)





More information about the ZPT mailing list