Jinja - Count the number of elements in a list

by
Jeremy Canfield |
Updated: November 25 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 }}
length can be used to get the count of elements in a list.
{% set fruits=['apple','banana','grape','orange'] %}
There are {{ print fruits|length }} elements in the fruits list
Did you find this article helpful?
If so, consider buying me a coffee over at