Create a collection of all pages using the same Template

What’s the best way to create a collection of all pages using the template “factory”?

Something like:

<?php $collection = page("factory");  ?>
<?php foreach ($collection as $factory): ?>
	    ...
<?php endforeach ?>

You can just use “filterBy”:

$collection = $site->index()->filterBy('template','factory');

Best,
Thomas

3 Likes

@thguenther is right, but if there is a way to narrow it down to the descendants of a particular page, I’d prefer that to going through the complete site index.

1 Like