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.

Support

Get a collection but only for a given template type

Solved by Domantas Bičkus View solution

Started by Usk70 9 years ago · 1 replies · 674 views
9 years ago

I have the following collection which selects latest pages from /blog.

page.find('/blog').collection({'items': '@self.descendants','order': {'by': 'date','dir': 'desc'}}).slice(2,1)

However, I would like to get only pages of template type 'blog.md'.
Is it possible to filter collection by template type too?

Thanks

9 years ago Solution

Yes it's possible by using .ofType() function.

There was a similar topic on how to use it in template: "/forum/archive/is-the-method-oftype-usable-in-a-collection-defined-with-twig-syntax-t2539"

👍 1

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 56 13 hours ago
Support · by Anna, 3 days ago
2 61 16 hours ago
Support · by Justin Young, 17 hours ago
1 32 17 hours ago
Support · by Duc , 1 week ago
2 66 5 days ago
Support · by Colin Hume, 1 week ago
2 59 5 days ago