Home

checked and selected in chameleon templates

Updated:
Created:

How to activate boolean attributes

When using chamelon templates using selected or checked as attributes in tal:attributes seems to fail, as the tag is rendered with something like selected=False.

The solution is somewhat hidden in the documentation. The solution is to activate boolean_attributes on the template:

template = PageTemplate("<input type="checkbox" tal:attributes="checked True" />",
                        boolean_attributes={"selected", "checked"})
// or

templates = PageTemplateLoader(path, boolean_attributes={"selected", "checked"})

I've created a pull request.

Update: pull request got accepted, yeah \o/