Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

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 · 950 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 blu3prince, 3 days ago
1 65 1 hour ago
Support · by complanar, 6 days ago
6 156 1 day ago
Support · by Rick Beebe, 7 days ago
2 115 3 days ago
Support · by alex, 5 days ago
2 101 4 days ago
Support · by Marcel, 2 weeks ago
1 151 4 days ago