[ZPT] Divmod() function?

Tino Wildenhain tino at wildenhain.de
Sun Jan 30 15:01:38 EST 2005


Am Sonntag, den 30.01.2005, 16:29 +0000 schrieb Jon Bowlas:
> Hi all,
> 
>  
> 
> I have I’m pretty certain the divmod() function is the answer to my
> problem, but being new to ZPT I have no idea how to use it in my
> particular instance.
> 
Whatever your problem is :-)

> 
> Let me try and explain my problem and hopefully someone will be able
> to help:
> 
>  
> 
> I have a collection of image objects contained within a folderish
> object and I would like to cycle through them using a ZPT adding a
> title_or_id of each object into a <td> tag of a <table> while I
> progress, however I only want to have a maximum of four <td>’s to a
> <tr>. 
> 
>  
> 
> Could anyone explain how this can be done using the divmod function,
> or any other function that will achieve the same results.
> 
You write a python script:

all_images=context.yourimagefolder.objectValues('Image')

table_width=5 # if you want 5 in a row

return [all_images[i:i+table_width] for i in
range(0,len(all_images),table_width)]  

 
You use this pyhon script then in your ZPT:

<table>
  <tr tal:repeat="row here/theScript">
    <td tal:repeat="img row"><img src="img" tal:attributes="src
img/absolute_url; width img/width; height img/height; alt img/getId;
title img/title" /></td>
  </tr>
</table>

like this or you skip the script and the table and
use CSS.

Btw, in mailinglists make sure you post in plain text only.

Regards
Tino



More information about the ZPT mailing list