Jinja - Return the first element in a list
by
Jeremy Canfield |
Updated: November 06 2023
| Jinja articles
first is a Jinja filter that can be used to return the first element in a list. Take for example the following.
{% set fruits=['banana','grapes','apples','pineapples'] %}
<br /><br />
Original List:
{{ fruits }}
<br /><br />
First Element in List:
{{ fruits | first }}
<br /><br />
First Element in Sorted List:
{{ fruits | sort | first }}
Something like this should be returned.
Original List: ['banana', 'grapes', 'apples', 'pineapples']
First Element in List: banana
First Element in Sorted List: apples
Did you find this article helpful?
If so, consider buying me a coffee over at