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