Jinja2 Structures

Variables :
var: {{ variable_name_here }}

Conditionals :
{% if var ==’value’ %}
text here
{% elif var ==’other value’ %}
text here
{% else %}
text here
{% endif %}

For Loops :
{% for item in list %}
text here
{% endfor %}

List :
list: {{ some_list[1] }}

Dictionary :
dict: {{ dict[“key”] }} orĀ {{ dict.key }}

Loop of a dictionary:
{% for key in dict %}
{{ key }}
{% endfor %}

{% for k,v in dict.items() %}
text here
{% endfor %}

 

Leave a Comment