tal:repeat question
After all the recent discussion around TAL, I've decided to finally take the time to get to know it better. So far, I must admit it's a lot easier than I thought it was from the looks of it and I have been able to convert almost an entire small site to TAL in an evening. However, one small puzzle remains for now. I wish to display a group of pictures in a 3 by 3 table. I'm currently doing that with the following dtml. Can anyone suggest how to do this in TAL? I've searched the archives and haven't been able to turn up anything that helps... <table> <dtml-in expr="objectValues('Image')" size=9 start=query_start> <dtml-if expr="_['sequence-index'] % 3 == 0"> <dtml-if expr="_['sequence-index'] > 0"> </tr> </dtml-if> <tr width="33%"> </dtml-if> <td class="photo_title"><dtml-var sequence-item></td> </dtml-in> </table> I know one way would be to call a python script that populated a list of lists containing the necessary objectValues, but I am curious as if that is the most efficient and/or only way. Thanks, Kevin
Kevin Carlson wrote:
I wish to display a group of pictures in a 3 by 3 table. I'm currently doing that with the following dtml. Can anyone suggest how to do this in TAL?
Unlike DTML, TAL doesn't try to build this sort of capability in, since it tends to become a mini-language. Instead, you can use the utility classes and functions in ZTUtils. Here is how I would write your example without using a Script (untested): <table tal:define="qs request/query_start; images python:objectValues('Image'); x3 python:range(3)"> <tr width="33%" tal:repeat="row x3"> <td class="photo_title" tal:repeat="col x3" tal:on-error="nothing"> <img src="example.gif" tal:replace="structure python:images[qs + row * 3 + col]" /> </td> </tr> </table>
I know one way would be to call a python script that populated a list of lists containing the necessary objectValues, but I am curious as if that is the most efficient and/or only way.
It would certainly make for a tidier template: <table> <tr width="33%" tal:repeat="row here/image_batch"> <td class="photo_title" tal:repeat="image row"> <img src="example.gif" tal:replace="structure image" /> </td> </tr> </table> Cheers, Evan @ 4-am
participants (2)
-
Evan Simpson -
Kevin Carlson