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? Dennis
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 - --On 29. November 2006 19:54:34 +0100 Dennis Schulz <d.schulz81@gmx.net> wrote:
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?
<div tal:replace="structure python: '<sometag>'" /> But you would better check if you really can't simplify your logic. - -aj -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) iD8DBQFFbdkgCJIWIbr9KYwRAhisAKCl+TfjUzdlyWMDS5tEQuF+8QoRigCeLJ8q fW77mKuOFVteXrNNkGsTMEs= =wOrG -----END PGP SIGNATURE-----
En/na Dennis Schulz ha escrit:
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?
Tricky and not tested from restricted code ... but you're asking for a tal solution: <table tal:define="l python:the_list + [ None ]; rows python:zip(l[0::2], l[1::2]); "> <tr tal:repeat="row rows"> <td tal:repeat="cell row"> </td> </tr> </table> An example:
the_list = [1,2,3,4,5,6,7,8,9] l = the_list + [ None ] zip(l[0::2], l[1::2]) [(1, 2), (3, 4), (5, 6), (7, 8), (9, None)]
the_list = [1,2,3,4,5,6,7,8,9,10] l = the_list + [ None ] zip(l[0::2], l[1::2]) [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
Instead of the tricky use of zip and extended slices write a more generic python script : convert_list_to_array(the_list, column_count=2) HTH
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
Tino Wildenhain schrieb:
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 "two"
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 :-)
ah yes, and I forgot the TAL: <table ..> <thead ... /> <tbody> <tr tal:repeat="row here/thescript or options/prepareddata"> <td tal:repeat="col row" tal:content="col">123</td> </tr> </tbody> </table> I guess you know what values you really want to put in :-) Regards Tino
participants (4)
-
Alexis Roda -
Andreas Jung -
Dennis Schulz -
Tino Wildenhain