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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Collection sorting

Started by Muut Archive 12 years ago · 3 replies · 548 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 1279 9 years ago
Archive · by Muut Archive, 9 years ago
2 886 9 years ago
Archive · by Muut Archive, 9 years ago
2 4015 9 years ago
Archive · by Muut Archive, 9 years ago
1 2891 9 years ago
Archive · by Muut Archive, 9 years ago
3 1075 9 years ago