filterBy Template - Can't get this to work

Think to the kirby demo site and how “team” within about doesn’t have a template associated to it. I want to filter by this specific template so that I can add other templates/pages bellow the about page.

I have tried things like

<?php foreach($page->children()->visible()->filterBy('template', '==', 'team') as $member): ?>

<?php foreach($page->children()->visible() as $member): ?>
<?php if($member->filterBy('template', '==', 'team')): ?>

The first example outputs nothing, the second outputs everything despite me changing team to awards etc…

Can someone direct me in the right direction?

Instead of using template() use intendedTemplate().

1 Like

OK, so template looks for the .php files and intendedTemplate looks for the name of the content file? Is that how I understand the difference there?

Yep, the intendedTemplate() methods looks for the name of the content file, whereas template() looks for the name of the content file and then checks if the template is registered.