Let's talk a bit …
Mar 18th
Omit attribute in TAL
I always tough than it was impossible to completely omit a tag attribute using TAL. So when I wanted to automatically check or not a radio button, I duplicated it like this:
<input type="radio" tal:condition="mycondition" checked="checked" />
<input type="radio" tal:condition="not:mycondition" />
But we can omit a tag attribute by passing nothing to a tal:attributes, like this:
<input type="radio" tal:attributes="checked python:mycondition and 'checked' or nothing" />
It’s so cleaner!
March 19, 2015 - 10:29 pm
I usually do tal:attributes=”python:’checked’ if mycondition else None”
March 20, 2015 - 12:59 pm
I wrote about this behavior (and other hidden features) some year ago:
http://blog.keul.it/2011/12/5-minutes-with-talattributes.html