krsort Twig Filter

The krsort filter sorts an array or hash in reverse order by its keys.

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

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = array|krsort %}
{% set hash = hash|krsort %}

You can use this filter within a for loop.

{% for item in items|krsort %}
...
{% 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]|krsort|join(', ') }}

That would output: 8, 5, 3, 2
This documentation is only for Aptuitiv CMS. Learn more.
Get Started With Aptuitiv