Basic usage
- variable x has content: {{ x }}
- expression: {{ x + 1 }}
- escaped for HTML: {{ x | e }}
Control structures
{% if x % 2 == 0 %}
{{ x }} is even!
{{ x }} is odd!
Whitespace trimming
these are
{{ "three" }}
lines.
this is conc
{{- "at" -}}
enated.
Special blocks
{ % raw %}
This is a raw block where {{nothing is evaluated}}
and <html is escaped> too with "e" filter
{ % endraw %}
this is a reusable macro, with arguments: {{x}}
{{ myfunc(42) }}
{#
this is a comment
#}
Inheritance
shared.html
<html>
<head>
<title></title>
</head>
<body>
<header><h1></h1></header>
<main></main>
</body>
</html>
home.html
Welcome to my site
This is the body
Library
Basic usage
from jinja2 import Template
template = Template('Hello {{ name }}!')
template.render(name='John Doe') == u'Hello John Doe!'