Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Collection sorting

Started by Muut Archive 12 years ago · 3 replies · 679 views
12 years ago

Hello,

I'm attempting to sort a collection, using the following:

TWIG
{% set collection = page.collection().sort(title, asc) %}

However this doesn't seem to work. If I drop the "sort" method the collection works. What am I doing wrong? Thanks.

12 years ago

if your page has children, then you can call sort on the page directly, eg page.sort. There is no sort method on the Collection object itself:

https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Page/Collection.php

If you want to sort on all pages however, you can do that with pages.sort,

Or like in the learn example, you can dynamically create a new collection based on taxonomy and also set the sort order:

{% set progress = page.collection({'items':{'@taxonomy.category': 'docs'},'order': {'by': 'default', 'dir': 'asc'}}) %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1662 9 years ago
Archive · by Muut Archive, 9 years ago
2 1122 9 years ago
Archive · by Muut Archive, 9 years ago
2 4282 9 years ago
Archive · by Muut Archive, 9 years ago
1 3162 9 years ago
Archive · by Muut Archive, 9 years ago
3 1286 9 years ago