Jinja 2

Loops

Breaking a loop

Source

You cannot break a loop in Jinja2:

Unlike in Python, it’s not possible to break or continue in a loop. You can, however, filter the sequence during iteration, which allows you to skip items. The following example skips all the users which are hidden:

{% for user in users if not user.hidden %}
    <li>{{ user.username|e }}</li>
{% endfor %}

Comments

Source

{# comment in a line #}

{#
  comment expanded
  to multiple
  lines
#}

filters

basename

# file.txt
{{ 'http://example.com/file.txt' | basename }}

dirname

# https://example.com/
{{ 'http://example.com/file.txt' | dirname }}