[ZPT] Deafening chirping of crickets
Shane Hathaway
shane at zope.com
Fri Apr 18 17:41:01 EDT 2003
Evan Simpson wrote:
> It provides if-elif-else functionality, but is more flexible and general
> than usual language constrcuts of this sort, since the association among
> the condition statements is name-based, not syntax-based.
>
> I can't think of a meaningful motivating example to show the value of
> this difference off the top of my head, so here's an arbitrary example
> of what's possible:
>
> <div tal:condition-group="group1;group2">
> <span tal:condition="group1 cond11">g1: 1</span>
> <span tal:condition="group2 cond21">g2: 1</span>
> <span tal:condition="group2 cond22">g2: 2</span>
> <span tal:condition="group1 cond12">g1: 2</span>
> <span tal:condition="python:not (group1 or group2)">Neither</span>
> <span tal:condition="group1 default">g1: no choice</span>
> <span tal:condition="group2 default">g2: no choice</span>
> </div>
>
> It will, of course, be much more common to do simple 2- or 3-way choices
> within a single group.
I think I get it... the Python equivalent would be something like this:
group1 = 1
if group1 and cond11:
group1 = 0
print "g1: 1"
if group2 and cond21:
group2 = 0
print "g2: 1"
if group2 and cond22:
group2 = 0
print "g2: 2"
if group1 and cond12:
group1 = 0
print "g1: 2"
if not (group1 or group2):
print "Neither"
if group1:
group1 = 0
print "g1: no choice"
if group2:
group2 = 0
print "g2: no choice"
This strikes me as quite difficult to explain. Something like
"tal:switch" and "tal:case" would be much easier to explain.
<div tal:switch="somevariable">
<span tal:case="string:A">do A stuff</span>
<span tal:case="string:B">do B stuff</span>
<span tal:case="default">do something else</span>
</div>
However, I agree with Jamie that speed is a more pressing concern.
Shane
More information about the ZPT
mailing list