Quoting "Jeffrey P Shell":
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>
Another way to do this is to use the python test() function inside tal:replace to conditionally replace the "if" content with the "else" content. For example: <div id="edit-area" tal:define="editItems python:here.getMenuItem(...)"> <h3>Edit Menu Items</h3> <form action="Delete" method="post" name="actForm" tal:replace="python:test(editItems, default, 'No menu items available')"> ... (form and table elements, and a loop over editItems contained in here if there were results) ... </form> </div> This technique works well when you have one case which is more "involved" and can be the default, and another case which is simple text (like an error message). -- 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
Brent Hendricks <brentmh@ece.rice.edu> wrote:
Another way to do this is to use the python test() function inside tal:replace to conditionally replace the "if" content with the "else" content. For example:
<div id="edit-area" tal:define="editItems python:here.getMenuItem(...)">
<h3>Edit Menu Items</h3> <form action="Delete" method="post" name="actForm" tal:replace="python:test(editItems, default, 'No menu items available')">
... (form and table elements, and a loop over editItems contained in here if there were results) ...
</form> </div>
This technique works well when you have one case which is more "involved" and can be the default, and another case which is simple text (like an error message).
This is very ugly, even if probably tempting for a PHP programmer :) Also if i18n comes into play, you'll have to use two different ways to internatonalize things... Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
participants (2)
-
Brent Hendricks -
Florent Guillaume