Cecil logo Cecil
What's on this page

Sorts

Sorting collections (of pages, menus or taxonomies).

sort_by_title

Sorts a collection by title (with natural sort).

{{ collection|sort_by_title }}

Example:

{{ site.pages|sort_by_title }}

sort_by_date

Sorts a collection by date (most recent first).

{{ collection|sort_by_date(variable='date', desc_title=false) }}

Example:

{# sort by date #}
{{ site.pages|sort_by_date }}
{# sort by updated variable instead of date #}
{{ site.pages|sort_by_date(variable='updated') }}
{# sort items with the same date by desc title #}
{{ site.pages|sort_by_date(desc_title=true) }}
{# reverse sort #}
{{ site.pages|sort_by_date|reverse }}

sort_by_weight

Sorts a collection by weight (lighter first).

{{ collection|sort_by_weight }}

Example:

{{ site.menus.main|sort_by_weight }}

sort

For more complex cases, you should use Twig’s native sort.

Example:

{% set files = site.static|sort((a, b) => a.date|date('U') < b.date|date('U')) %}