The rsort filter sorts an array in reverse order.

You would typically save the sorted array back to the original variable or to a new variable.

{% set array = array|rsort %}

You can use this filter within a for loop.

{% for item in items|rsort %}
{% endfor %}

You can also use this filter in combination with the join filter to sort and output the array values in one step.

{{ [5,8,2,3]|rsort|join(', ') }}

That would output: 8, 5, 3, 2

< Back to the list of filters