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

Fergal Daly fdaly at sift.co.uk
Fri Aug 1 11:00:07 EDT 2003


I remember briefly reading that and not getting it but now I do. The only 
thing is that I'm not so sure you should overload tal:condition to have a 1 
arg and a 2 arg meaning. I think it makes it trickier to parse. You can't 
tell whether the thing you're parsing is an expression or a group name until 
after you've parsed it.

I'm not sayng this is good but how about something like tal:group and 
tal:group-condition? Or how about putting the expression first. For even more 
wackiness you could then follow it with multiple condition group names! Maybe 
not...

In your email you give this as an example of subtle interaction with loops:

<tal:x condition-group="fred">
   <tal:x condition="fred default">Always</tal:x>
   <tal:loop repeat="n python:range(3)" condition-group="fred">
     <tal:x condition="fred repeat/n/first">First</tal:x>
     <tal:x condition="not:fred">Not First</tal:x>
     <tal:x condition="fred repeat/n/last">Last</tal:x>
   </tal:loop>
   <tal:x condition="fred default">Never</tal:x>
   <tal:x condition="fred">Always</tal:x>
</tal:x>

the not:fred vs fred default being a crucial point. Is it not just the case 
that you should have put the "Not First" line last, I'm sure that's what you 
would have done if you were writing and if/elsif/else in Python. Actually in 
an if/elsif/else language that whole thing would have had the loop outside 
the condition group but maybe that was what you were showing?

I find condition groups clever but a bit weird and I think you can do 
confusion stuff like interleaved if/elsif/elses and putting unconditional 
stuff in the middle of conditional control structures a bit like (aplogies 
for perlishness)

if($a == 0)
{
	print "zero\n"
}
print "weird\n"
else
{
	print "not zero\n";
}

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>

It would be illegal to put anything besides whitespace in the gaps between 
conditions and between the conditions and the groups. Of course there are 
thing you can do with your groups that you can't do with mine but I find them 
hard to think about.

Or maybe more useful is a switch style construct.

<tal:x tal:switch="user/isLoggedIn">
  <tal:x tal:case="true">
    Welcome
  </tal:x>
  <tal:x tal:case="default">
    Please login
  </tal:x>
</tal:x>

This raises the obvious question of how comparisons are done, but I'm just 
thinking out loud. Advantages are that it nests but can't nest weirdly and 
there's no need to name the group. It's also a construct familiar to 
everyone.

F

On Thursday 31 July 2003 18:29, Evan Simpson wrote:
> Fergal Daly wrote:
> > Are either of these on the cards or does someone have a really clever
> > idea brewing?
>
> A while back, I proposed tal:condition-group, which is much more
> powerful and well-defined than "else", but harder to understand.  Your
> example would be written:
>
> <tag tal:condition-group="blah">
>    <tag tal:condition="blah here/someexpensivetest">
>      something
>    </tag>
>    <tag tal:condition="blah default">
>      something else
>    </tag>
> </tag>
>
> It extends to multi-way tests, and has several subtle features.  See:
>
> http://mail.zope.org/pipermail/zpt/2003-April/004509.html
>
> Cheers,
>
> Evan @ 4-am
>
>
>
> _______________________________________________
> ZPT mailing list
> ZPT at zope.org
> http://mail.zope.org/mailman/listinfo/zpt

-- 
Fergal Daly
Web Developer
Sift, 100 Victoria Steet, Bristol, BS1 6HZ
tel:+44 117 915 9600  fax:+44 117 915 9630   http://www.sift.co.uk




More information about the ZPT mailing list