Get a collection but only for a given template type

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

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

There was a similar topic on how to use it in template: “Is the method ofType usable in a collection defined with twig syntax?

1 Like