[ZPT] If/else?
Brent M Hendricks
brent@valinor.waldenweb.com
Wed, 9 May 2001 13:26:07 -0500
Hello,
I thought that this would be easy with ZPT, but I can't seem to figure
it out. It's probably obvious, but I've been staring at it so long I
can't see it. Here is my situation. Based on the output of a python
expression, I would like to either replace the current element (and
its children), or leave it unchanged.
My first inclination was to try this:
<div tal:condition="python:doChange()" tal:replace="....">
.. some default stuff...
</div>
This doesn't work though, because if doChange() is false then the
tal:condition causes the whole <div> to be omitted. My second thought
was to use some combination of the new if/exists path modifiers.
However those only seem to work when the condition is dependent upon
the thing you are using for the replace.
I know I could achieve the effect by putting in two <div> tags, but
that defeats the purpose of having the template look like the finished
product.
Any advice? This seems to me like a pretty common use-case scenario.
Thanks,
Brent
-------------------------------------------------------------------------
"The programmer, like the poet, works only slightly removed from pure
thought-stuff. He builds his castles in the air, from air, creating
by exertion of the imagination. Few media of creation are so
flexible, so easy to polish and rework, so readily capable of
realizing grand conceptual structures."
-- Frederick Brooks, Jr., The Mythical Man Month