Site filterby template?

Hi,

my structure looks like that:

  • wonderful-world
    -> folder
    -> locations
    -> folder
    - usw…
  • amazing-world
  • strange-world

template:
What I want todo is, to get all pages with a specific template inside from one of the root folders.

$site->index()->filterBy('template','locations');

That works, but with that I got the locations from every root folder.

so like that…

$page(‘wonderful-world’)->children()->filterBy(‘template’,‘locations’);

but that search just in one level.

I hope it is clear what I mean with that, thank you for your help.

1 Like

Try

$pages->find('wonderful-world')->children()->filterBy('template','locations');

There’s also “intendedTemplate” which comes in handy if you name a content .txt file one thing, but the template/blueprint files don’t exist. So if there was no ‘locations.php’ template, it “template” would be “default” but intendedTemplate would be “locations”.

http://getkirby.com/docs/cheatsheet

1 Like

thanks for your quick answer but, does’t work :frowning:

page('wonderful-world')->index()->filterBy(…)

http://getkirby.com/docs/cheatsheet/page/index

1 Like

It appears @distantnative has a solution as well. As for the one I presented, I’m not sure why it didn’t work for you.

I tried this both ways and it worked fine.

<?php

$locations = page('home')->index()->filterBy('intendedTemplate','_section');

foreach($locations as $location):
    echo "Location = " . $location->title();
endforeach;

?>


<?php

$locations = $pages->find('home')->children()->filterBy('intendedTemplate','_section');

foreach($locations as $location):
    echo "Location = " . $location->title();
endforeach;

?>
1 Like

works works!!! yeah thanks was my mistake :+1: