[ZPT] Extending tal:condition, making metal:define

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Thu, 05 Apr 2001 13:54:58 +1000


Evan Simpson wrote:
> 
> Here's two ideas I had while using ZPT today:
> 
> 1. Suppose that I want to replace a tag, but only if the replacement
> value exists, otherwise I want to keep the dummy text.  Right now, this
> is the best I can do:
> 
> <span tal:condition="exists:request/foo"
> tal:replace="request/foo"></span>
> <span tal:condition="not:exists:request/foo">The Text</span>
> 
> Ditto for 'content' and 'attributes'.  This isn't that bad, but I
> thought about extending 'condition', so that you could write:
> 
> <span tal:condition="replace exists:request/foo"
> tal:replace="request/foo">The Text</span>

Another approach would be to have the condition be able to break out of the
processing for that tag if it fails, and not remove the tag. Something
like:

  <span tal:condition="noremove:exists:request/foo"
tal:replace="request/foo">The Text</span>

Or maybe a whole new TAL statement is required?

  <span tal:sticky_condition="exists:request/foo"
tal:replace="request/foo">The Text</span>

or

  <span tal:lazy_replace="request/foo">The Text</span>


Perhaps what we really want is a way for replace to fail gracefully?

  <span tal:replace="only_if_exists:request/foo">The Text</span>


My favourite is a tie between the last two... They're probably easier to
actually implement, and it's much more obvious what they're doing. Not that
we'd have to go with 'only_if_exists' as the actual keyword ;)


    Richard

--
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)