[ZPT] Extending tal:condition

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Mon, 09 Apr 2001 09:24:39 +1000


Guido van Rossum wrote:
> 
> > The sort of thing I'm thinking of, call it "if:", would evaluate it's
> > expression and catch any traversal errors (traversal would be modified
> > to raise a new exception if a step failed in any way).  On such an
> > error, it would return (or raise) doNothing.  TALInterpreter would be
> > modified so that 'content', 'replace', and 'attributes' would do nothing
> > if they receive this signal.  That way we could write:
> >
> > <p tal:content="if:request/might_be_here">It isn't here.</p>
> >
> > If "path:request/might_be_here" resolves, then its value replaces the
> > paragraph content, otherwise the default text remains.  Likewise:
> >
> > <a href="/default.html" tal:attributes="href if:here/goto">Go here</a>
> >
> > "if::" could also be "optional:", or whatever.
> 
> OK, good.  Now I understand.  Should we do this for 1.1?  (It's not
> hard!)

As long as I don't have to wait too long for 1.1, I'm happy for this. I'm
using 'lazy' at the moment, and it won't be too hard renaming it to
whatever the keyword ends up being.

My vote is against 'if' and 'optional'. 'if' could be confused too easily
with the semantics of tal:condition. It implies that there's more going on
- that the path is being evaluated for truth. 'optional' doesn't really
have any indication of what's really going on.

Is there some reason why we couldn't just make use of 'exists'? It has no
real use in the content/replace TAL operations. Make doNothing a false
value. Or is that overloading the 'exists' keyword too much? And what's the
behaviour of the test in tal:replace? I think it'd be the same as
replace/content - the tag stays as is, with no further processing.


    Richard

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