[ZPT] Re: TAL's lack of an else...

Fergal Daly fergal at esatclear.ie
Fri Aug 1 16:52:31 EDT 2003


On Friday 01 August 2003 14:24, Tino Wildenhain wrote:
> where does the temp_cond come from? why not using user/isLoggedIn
> everywhere instead?

Because evaluating expressions more than once might be a bad idea.
> Simple rule of thumb: (1) when it becomes complicated to do with TAL,
> you pobably do something the wrong way. Redesign your application in
> this case.

Perhaps you would like to have a word with the the authors of Zope and explain 
how their application is badly designed. A grep on Zope 2.7.0.b1 turns up

./import/Examples.zexp:tal:condition="subfolders"
./import/Examples.zexp:tal:condition="not:subfolders"

./import/Examples.zexp:tal:condition="siblings"
./import/Examples.zexp:tal:condition="not:siblings"

./import/Examples.zexp:tal:condition="exists:request/message"
./import/Examples.zexp:tal:condition="python:previous or next"
./import/Examples.zexp:tal:condition="previous"
./import/Examples.zexp:tal:condition="next"

./import/Examples.zexp:tal:condition="files"
./import/Examples.zexp:tal:condition="not:files"

./import/Examples.zexp:tal:condition="current_items"
./import/Examples.zexp:tal:condition="not:current_items"

./import/Examples.zexp:tal:condition="entries"
./import/Examples.zexp:tal:condition="not:entries"

As you can see, almost _every_ condition there is actually an if/else and 
that's just the Examples. There are lots of other templates doing the same 
thing. They would use if/else if they could but they can't because it doesn't 
exist. What you will see if you look in the file is that in all the if/else 
constructs they first define a temporary variable to hold the truth value, 
then they test it.

So assuming the authors of Zope are not clueless, it seems pretty clear to me 
that TAL _should_ have a safe, efficient and clear if/else construct. People 
(and that includes very clever people who know lots about ZPT) are doing it 
in their templates, we should make it easy and safe by accommodating it in 
the template language.

F




More information about the ZPT mailing list