Hello,
I'm attempting to sort a collection, using the following:
{% 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.
Community guidelines
Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.
Hello,
I'm attempting to sort a collection, using the following:
{% 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.
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'}}) %}
Hope that helps...
Thanks, that clears up the confusion.
Log in to reply.
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 0 | 1279 | 9 years ago | ||
| 2 | 886 | 9 years ago | ||
| 2 | 4015 | 9 years ago | ||
| 1 | 2891 | 9 years ago | ||
| 3 | 1075 | 9 years ago |