ZPT condition attribute question
hello, i have an input tag, and i want to set the value attribute to either a defined value or a blank string. my python expression either returns a single instance or an empty list. right now, i am using two Input tags in tandem. Only one remains after rendering b/c one is removed. my question, is it possible to write this so i don't have to have nearly identical Input tags all over my page? thanks, mark <input type="text" name="input_name" tal:condition="task/task_name | nothing" tal:attributes="value task/task_name" /> <input type="text" name="input_name" tal:condition="not:exists:task/task_name" tal:attributes="value string:hi" />
On Tuesday 21 May 2002 1:04 pm, Mark A. Lilly wrote:
hello, i have an input tag, and i want to set the value attribute to either a defined value or a blank string. my python expression either returns a single instance or an empty list.
right now, i am using two Input tags in tandem. Only one remains after rendering b/c one is removed. my question, is it possible to write this so i don't have to have nearly identical Input tags all over my page?
thanks, mark
<input type="text" name="input_name" tal:condition="task/task_name | nothing" tal:attributes="value task/task_name" />
<input type="text" name="input_name" tal:condition="not:exists:task/task_name" tal:attributes="value string:hi" />
The obvious way to do this is something like: <input type="text" name="input_name" tal:attributes="value task/task_name | string:hi" /> but I have tried that before and it doesn't seem to work, as I presume you have already discovered. My solution to this is to use a Python 'or' instead of the ZPT '|' character to specify a default, and make the whole thing a Python expression: <input type="text" name="input_name" tal:attributes="value python:task['task_name'] or 'hi'" /> That's not quite as pretty as the pure TAL style but it seems to work. Harry
On Tue, May 21, 2002 at 05:04:38AM -0700, Mark A. Lilly wrote:
hello, i have an input tag, and i want to set the value attribute to either a defined value or a blank string. my python expression either returns a single instance or an empty list.
right now, i am using two Input tags in tandem. Only one remains after rendering b/c one is removed. my question, is it possible to write this so i don't have to have nearly identical Input tags all over my page?
thanks, mark
<input type="text" name="input_name" tal:condition="task/task_name | nothing" tal:attributes="value task/task_name" />
<input type="text" name="input_name" tal:condition="not:exists:task/task_name" tal:attributes="value string:hi" />
The condition seems not to be necessary at all: <input type="text" name="input_name" tal:attributes="value task/task_name | nothing" /> should work for the first example -- well, I have only tested <input type="text" name="input_name" value="some_thing" tal:attributes="value task/task_name | nothing" /> I think the second can be expressed as (not tested): <input type="text" name="input_name" value="hi" tal:attributes="value not:exists:task/task_name | default"> Jim Penny
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Harry Wilkinson -
Jim Penny -
Mark A. Lilly