# Writing templates If you arrive from Jinja, Chameleon will feel upside down for about an hour. Jinja puts its logic in the text, between `{% %}` and `{ }` markers, and the HTML flows around it. Chameleon puts its logic on the elements, as `tal:` attributes, and the HTML stays HTML. After the hour it feels inevitable: there is no element you can forget to close, because the template is a document, and the browser will tell you when it isn't. This page is the working subset. Every snippet on it was rendered with the Chameleon release the library installs, so the output shown is the output you get. The full language is documented at [chameleon.readthedocs.io](https://chameleon.readthedocs.io/). # Interpolation: `${...}` Values from the model drop in through `${...}`, and the expression inside is ordinary Python: ``` html
You have ${len(items)} item(s).
${'Welcome back' if user else 'Please sign in'}
``` Everything is HTML-escaped on the way in. A model value of `bold` renders as `bold`, which is what you want for anything a user typed. When a value is already safe HTML, say a rendered Markdown document, prefix the expression with `structure:` to insert it verbatim: ``` html${subtitle | 'No subtitle'}
${tracking_id | nothing}
``` `nothing` is Chameleon's spelling of `None`; it renders as an empty string. # Loops: `tal:repeat` `tal:repeat="item items"` repeats the element it sits on once per item: ``` htmlTotal: ${total}
``` `tal:omit-tag=""` renders an element's contents without the element, useful when you need somewhere to hang a `tal:repeat` or `tal:define` but want no wrapper in the output: ``` html${section.body}