Twig :: order

The order filter will sort an array of associative arrays or stakx objects based on a key

Since

0.1.0

Usage

order(key, order = 'ASC')

Parameters

  • (required) key : string

    The key to sort by

  • order : string

    'ASC' or 'DESC'

Example Usage

In a blog, displaying posts in reverse chronological order is the accepted practice. Using the order filter lets you achieve this.

{% for post in collections.posts | order('date', 'DESC') %}
  <article>
    <h1>{{ post.title }}</h1>

    <!-- ... -->
  </article>
{% endfor %}