Jinja - Getting Started with Lists

by
Jeremy Canfield |
Updated: June 20 2024
| Jinja articles
Here is a basic example of how to create and print a list in Jinja.
{% set fruits=['apple','banana','grape','orange'] %}
{{ print fruits }}
And here is a basic example of how to loop over a list of values in Jinja.
{% set fruits=['apple','banana','grape','orange'] %}
{% for fruit in fruits %}
{{ fruit }}
{% endfor %}
Or, you can print a specific index item from the list. In this example, index item 0 (apple) will be printed.
{% set fruits=['apple','banana','grape','orange'] %}
{% for fruit in fruits %}
{{ fruit[0] }}
{% endfor %}
Did you find this article helpful?
If so, consider buying me a coffee over at