[Zope] Re: tal:repeat question
Evan Simpson
evan@4-am.com
Wed, 19 Feb 2003 16:38:23 -0600
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