Let's talk a bit …
Posts tagged TAL
Omit attribute in TAL
Mar 18th
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!