[ZPT] Mini proposal: repeat-define and repeat-condition

Shane Hathaway shane@zope.com
Mon, 20 Jan 2003 17:10:20 -0500


Problem

In TAL I find that I frequently have to invent tags just to execute some 
condition or variable definition repeatedly.  For example:

<tr tal:repeat="item here/objectItems">
  <tal:block tal:condition="python: item[1].date < expiration"
             tal:define="key python: item[0]; value python: item[1]">
   <td>...</td>
   <td>...</td>
  </tal:block>
</tr>

I can't put the tal:condition and tal:define attributes in the <tr> tag, 
since then they would be executed only once, before the loop.  But I'd 
really like to avoid the need for "tal:block", while checking the 
condition and making the "key" and "value" variables available when 
presenting the table cells.

Proposed Solution

Add two new TAL attributes, "repeat-define" and "repeat-condition". 
These have the same semantics as "define" and "condition", respectively, 
  but when combined with a "repeat" attribute, they get executed once 
per loop iteration.  I would be able to rewrite the above example like this:

<tr tal:repeat="item here/objectItems"
     tal:repeat-define="key python: item[0]; value python: item[1]"
     tal:repeat-condition="python: value.date < expiration">
  <td>...</td>
  <td>...</td>
</tr>

What do you think?

Shane