[Zope] hasattr in tal:condition
Jean-Francois.Doyon at CCRS.NRCan.gc.ca
Jean-Francois.Doyon at CCRS.NRCan.gc.ca
Mon Mar 15 16:07:23 EST 2004
Well, the thing about duplicating HTML in a ZPT due to the condition
handling isn't new ... I've had to do that duplication thing myself a few
times, not very elegant, but a small price to pay for the coolness of ZPT's
otherwise :)
Using PythonScripts is one idea, but the more ZPT'ish way to go about this
might be to use METAL macros ... In fact someday I'll have to go look at my
code to see if that wouldn't make much more sense.
One other option is to tal:define the result of the condition, and then use
the variable to do further conditional testing in your body or span. But
like you said, that could clutter the whole thing with lots of tests, in
which case the duplication is actually more efficient logic-wise ...
It really depens on how much your true/false HTML has in common ...
J.F.
-----Original Message-----
From: zope-bounces at zope.org [mailto:zope-bounces at zope.org]On Behalf Of
Troy Farrell
Sent: Monday, March 15, 2004 3:54 PM
To: Andre Meyer
Cc: zope List
Subject: Re: [Zope] hasattr in tal:condition
I haven't been following this thread, but your suggestion seems silly. Use
two
lines in one Page Template:
<span tal:condition="exists: here/request/results" />
<span tal:condition="not: exists: here/request/results" />
Even better, write a python script which returns what you want to display
and
use one line in the ZPT:
<span tal:define="results container/myscript"
tal:content="results/stuff" />
Sorry if my suggestions are irrelevant. I'm trying to keep you from doing
unnecessary work.
Troy
Andre Meyer wrote:
> Thanks for the hint.
>
> After some experimentation I realise that "exists:" does not help,
> because it does not have an "else" branch. If I set the exists condition
> on the body or a span tag, the defined results are visible only within
> that tag. An else branch must me simulated by a second condition on a
> tag, but that means that the whole content of the previous one needs to
> be repeated. However, the whole point of the test was to re-use all the
> content except for a single statement at the beginning that determines
> where the results come from. As a result, a neater solution seems to be
> to have two ZPTs with a single different line (maintenance problem).
>
> regards
> Andre
>
>
> Jean-Francois.Doyon at CCRS.NRCan.gc.ca wrote:
>
>> Yes, use the "exists:" TAL expression. So you would do:
>>
>> <span tal:condition="exists: here/request/results" />
>>
>> or something like that ...
>>
>> More info in the ZPT reference ...
>>
>> J.F.
_______________________________________________
Zope maillist - Zope at zope.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
More information about the Zope
mailing list