Jinja - Sort a List
by
Jeremy Canfield |
Updated: January 16 2024
| Jinja articles
sort is a Jinja filter that can be used to:
- sort a dictionary
- sort a list (this article)
Take for example the following.
{% set integers=[3,20,1] %}
<br /><br />
Original List:
{{ integers }}
<br /><br />
Sorted List:
{{ integers | sort }}
<br /><br />
Sorted List in Reverse order:
{{ integers | sort(reverse=true) }}
Something like this should be returned.
Original List: [3, 20, 1]
Sorted List: [1, 3, 20]
Sorted List in Reverse order: [20, 3, 1]
Did you find this article helpful?
If so, consider buying me a coffee over at