[Zope] tal loop to render table

Tino Wildenhain tino at wildenhain.de
Wed Nov 29 15:29:25 EST 2006


Dennis Schulz schrieb:
> I would like to build a tal loop that renders a list of elements 
> (widgets in my case) in a table.
> (for example I have a list of 9 items, then it renders a table: five 
> rows with 2,2,2,2,1 items)
> the table has 2 columns, so i would need to open and close the table row 
> every second item.
> I tried to check with a condition if the row is odd or even, but 
> unopened and unclosed tags are not valid.
> 
> Is there any possibiliy to do this with tal?

Well, you just dont want to do this in TAL, really ;)
You have to choices: either not using a table but
a couple of carefully CSS-crafted <div> tags
(See alistapart.com or so for hints on tableless floating
designs)

Or you go the easy path and have a data preparing script
(Script (Python) - Object) which does something along the lines
of:

data=your_nine_items

rowlength=2

return [data[i:i+rowlength] for i in range(0,len(data),rowlength)]


I think you get the idea :-)

Regards
Tino


More information about the Zope mailing list