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

Fernando Martins fmartins@hetnet.nl
Thu, 23 Jan 2003 00:22:23 +0100


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

This is the grammar for tal:repeat:

argument ::= variable_name expression
variable_name ::= Name

How about having the grammar:

argument ::= variable_name expression [; condition] [;define-var]*
define_var ::= variable_name expression
variable_name ::= Name
condition ::= expression

Or, more flexible but with tricky semantics:

argument ::= variable_name expression [;define-var | condition]*
define_var ::= variable_name expression
variable_name ::= Name
condition ::= expression

Tricky semantics because all the conditions except the last one would decide
on the execution of the remaining repeat statements. The last condition
would then decide whether or not to write the contents inside the repeat
html element. Also, probably we would like then to have an "else"
facility...

Regards,
Fernando