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

Fergal Daly fdaly at sift.co.uk
Fri Aug 1 14:55:05 EDT 2003


On Friday 01 August 2003 13:42, Jean-Michel Hiver wrote:
> > How about something more traditional but hopefully as powerful in most
> > situations.
> >
> > <tal:x tal:condition-group>
> >   <tal:x tal:condition="user/isLoggedIn">
> >     welcome
> >   </tal:x>
> >   <tal:x tal:condition="default">
> >     please login
> >   </tal:x>
> > </tal:x>
>
> I don't know what the others think, but I think this is looking like an
> ugly mess.

Yep, but that's programming in XML for you. Anyway, the alternative if even 
worse

<tal:x tal:define="temp_cond_var user/isLoggedIn">
  <tal:x tal:condition="temp_cond_var">
    welcome
  </tal:x>
  <tal:x tal:condition="not:temp_cond_var">
    please login
  </tal:x>
</tal:x>

and that's without even trying to do an "elsif" and you better make sure that 
"temp_cond_var" doesn't clash with any variables inside your conditions.

> I like TAL because it's got very few instructions with which you can do
> a lot. If the syntax starts to have condition-group, repeat-define and
> others, then it'll quickly become some horrible attribute-soup.

Absolutely but I think that not having "else" is a serious deficiency. If you 
can point me to another vaguely respectable template language that doesn't 
have "else" I'll buy you a pint!

> * it deprecates an equal or greater set of statements
> * it is equally or more expressive than the previous set
> * you don't need to be a nobel prize to understand it
>
> - OR -
>
> * it provides completely orthogonal functionality (i.e. on-error and
> condition are orthogonal. else, in comparison, is really just another
> kind of condition.

With a bit of renaming of the above, how about something like this

<tal:x tal:if-else>
  <tal:x tal:if="user/isLoggedIn">
    welcome
  </tal:x>
  <tal:x tal:else>
    please login
  </tal:x>
</tal:x>

Still not pretty but I don't think it's ever going to be pretty,

F



More information about the ZPT mailing list