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

Jean-Michel Hiver jhiver@mkdoc.com
Wed, 22 Jan 2003 16:56:36 +0000


On Mon 20-Jan-2003 at 05:10:20PM -0500, Shane Hathaway wrote:
> 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>

How about you do:

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

?

Sure, the <span> is a bit ugly but you didn't actually have to INVENT
another tag and it does not appear in your output...


> 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>

Despite the workaround mentioned above I quite like that solution I must
admit :-)


Cheers,
-- 
Building a better web - http://www.mkdoc.com/
---------------------------------------------
Jean-Michel Hiver
jhiver@mkdoc.com  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/