{% for user in users | sort %}
  ...
{% endfor %}

You can pass an arrow function to sort the array:

{% set fruits = [
  { name: 'Apples', quantity: 5 },
  { name: 'Oranges', quantity: 2 },
  { name: 'Grapes', quantity: 4 },
] %}

{% for fruit in fruits | sort((a, b) => a.quantity <=> b.quantity) | column('name') %}
  {{ fruit }}
{% endfor %}

Note the usage of the spaceship operator to simplify the comparison.

Arguments

ArgumentDescriptionType
arrowThe arrow functionFunction

Was this helpful?

Copyright © 2024 Blutui.