[Zope-dev] ZPT and 'else'

Marc Lindahl marc@bowery.com
Thu, 09 May 2002 23:39:32 -0400


Yecch!

Why not:
<if ...>
True stuff
</if>
<else>
False stuff
</else>

If leaves around boolean result, else picks up the most recent one... It's
like they push on a stack so you can nest them.... Something like that?


on 5/9/02 11:10 PM, Jeffrey P Shell at jeffrey@cuemedia.com scrivened:

> 'else' is tricky within the block oriented structure of anything XML-ish,
> because of the concept of 'well-formedness'.  The 'if' statement would have
> to be singly wrapped, and the else block wrapped separately, looking at
> least somewhat awkward any way you go about it.  The best I can come up with
> in my mind is this, in order to have the 'else' pick up on the condition
> expressed in its surrounding container.  But, yuck:
> 
> <if ...>
> true stuff
> <else>
> false stuff
> </else>
> </if>
> 
> 
> A good page template way is something like this:
> 
> <tal:if condition="myTalesExpression">
> truth
> </tal:if>
> <tal:else condition="not:myTalesExpression">
> false
> </tal:else>
> 
> The 'not' TALES namespace is valuable.  The downside is that you evaluate
> the expression twice.  A good way to work within this is something that I
> did earlier today, outside of this conversation, where I evaluate an
> expression earlier and assign it to a variable:
> 
> <div id="edit-area"
>    tal:define="editItems python:here.getMenuItem(...)">
> 
> <h3>Edit Menu Items</h3>
> <form action="Delete" method="post" name="actForm"
>       tal:condition="editItems">
> 
>    ... (form and table elements, and a loop over editItems
>         contained in here if there were results) ...
> 
> </form>
> 
> <div class="emph"
>      tal:condition="not:editItems">
>  No menu items available
> </div>
> 
> </div>
> 
> 
> This is something I did a lot in DTML too, setting a search result to either
> a global variable, or inside of a large <dtml-let> namescape