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

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Fri, 06 Apr 2001 11:50:36 +1000


richard@bizarsoftware.com.au wrote:
> richard@bizarsoftware.com.au wrote:
> > 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>
> 
> Just a note: I've implemented a "lazy" keyword so that one can:
> 
>   <span tal:replace="lazy:request/foo">The Text</span>
>   <input name="foo" value="" tal:attributes="value lazy:request/foo">
> 
> I currently have a patched Expressions.py using Shane's fixes to
> restrictedTraverse, so a diff to provide this functionality is going to be
> unusable. In short though, I modified installHandlers so 'lazy' is
> recognised, and added a clause to the "except (AttributeError, KeyError):"
> in PathExpr.__call__ with "if self._name == 'lazy': return None".
> 
> This works a treat for me - I use it in tal:attributes and tal:replace at
> the moment.

Oops - just realised that the replace behaviour isn't what Evan wanted...
The lazy evaluation is still a very big bonus though. Hrmm...


   Richard

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