Skip to content
● Critical PHP security fixes are out: update PHP on your Grav sites. What to do →

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 · 1064 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 webmasterodp, 2 weeks ago
4 248 2 weeks ago
Support · by nwhitfield, 2 weeks ago
2 213 2 weeks ago
Support · by stell, 4 weeks ago
5 458 3 weeks ago
Support · by gravinator, 2 months ago
5 637 3 weeks ago
Support · by Gravver, 1 month ago
6 430 4 weeks ago