[ZPT] tal:repeat and variables

Fernando Martins fmartins@hetnet.nl
Thu, 13 Feb 2003 20:59:46 +0100


Troy Farrell wrote:
> Clemens Robbenhaar wrote:
>  > <snip>
>  >
> >  I don't think there is a better way. The tal:repeat is just designed in
> > a way that all elements in a repeat are rendered nearly independent of
> > each other.
> >
> >  Despite it is actually presentation logic and not application logic, I
> > would tend to filter the result set through a python script, replacing
> > the unwanted entries by empty strings. I did not work with SQL result
> > sequences, but I guess one maybe has to make a copy of the result
> > sequence, as the original sequence may be immutable.
> I'd have to agree: this is a job for a python script.  I would make a
> dictionary of tuples (or lists) like this:
> {'Computers': ('John','Dilvert','Smith')
> ,'Software': ('Peter','Mary',)
> }
> <table>
>    <span tal:omit-tag=""
>          tal:repeat="k python:data.keys()">
>      <tr tal:repeat="d data[k]">
>        <td tal:content="k"
>            tal:condition="repeat/d/start"/>
>        <td tal:content="d">
>      </tr>
>    </span>
> </table>
> The code is untested, but I hope that helps you out...

Albeit for the type of table presented I prefer Evan's solution, this is
also a helpeful technique. Thanks.

For the record, the debugged code is:

   <span tal:omit-tag=""
         tal:repeat="k python:data.keys()">
     <tr tal:repeat="d python:data[k]">
       <td tal:condition="repeat/d/start"
           tal:attributes="rowspan python:len(data[k])"/>
       <td tal:content="d"/>