pub fn sort(
state: &State<'_, '_>,
value: Value,
kwargs: Kwargs,
) -> Result<Value, Error>Expand description
Returns the sorted version of the given list.
The filter accepts a few keyword arguments:
case_sensitive: set totrueto make the sorting of strings case sensitive.attribute: can be set to an attribute or dotted path to sort by that attribute. can be a comma-separated list of attributes forming a composite key like “age, name”.reverse: set totrueto sort in reverse.
{{ [1, 3, 2, 4]|sort }} -> [4, 3, 2, 1]
{{ [1, 3, 2, 4]|sort(reverse=true) }} -> [1, 2, 3, 4]
# Sort users by age attribute in descending order.
{{ users|sort(attribute="age") }}
# Sort users by age attribute in ascending order.
{{ users|sort(attribute="age", reverse=true) }}
# Sort cities by their name, and sort those with the same name by their state.
{{ cities|sort(attribute="name, state") }}