Line Statements
If line statements are enabled by the application, it’s possible to mark aline as a statement. For example, if the line statement prefix is configuredto #
, the following two examples are equivalent:
<ul>
# for item in seq
<li>{{ item }}</li>
# endfor
</ul>
<ul>
{% for item in seq %}
<li>{{ item }}</li>
{% endfor %}
</ul>
The line statement prefix can appear anywhere on the line as long as no textprecedes it. For better readability, statements that start a block (such asfor, if, elif etc.) may end with a colon:
# for item in seq:
...
# endfor
Note
Line statements can span multiple lines if there are open parentheses,braces or brackets:
<ul>
# for href, caption in [('index.html', 'Index'),
('about.html', 'About')]:
<li><a href="{{ href }}">{{ caption }}</a></li>
# endfor
</ul>
Since Jinja 2.2, line-based comments are available as well. For example, ifthe line-comment prefix is configured to be ##
, everything from ##
tothe end of the line is ignored (excluding the newline sign):
# for item in seq:
<li>{{ item }}</li> ## this comment is ignored
# endfor