Accessing a child page from page children collection

For an existing template, I’ve created a new controller:


return function($site, $pages, $page) {

  $banner = $page->children()->filterBy('template', 'banner')->first();

  return compact('banner');


In the corresponding template for this controller, $banner isn’t defined and I can’t access any attributes of the child page.

Looking for help as I can’t see what I’m doing wrong.


Are the file names of controller and template exactly the same? Is you variable in the template spelled correctly?

If there are no spelling mistakes, please post the template. and maybe. a screenshot of the error message.

Thanks for your reply.

I’ve got this working with intendedTemplate, which I read about here: Filter child pages by template not working. I think I’ve got the same set up.

The children pages are based on a template defined under “snippets”.

Yes, template only works if there is a template for the page in the /site/templates folder, the files in the snippets folder are called snippets. and you can’t filter by snippets.