Filter subpages in blueprint pages field query

I’ve been searching like crazy but can’t find anything. (maybe I just need to get some sleep :thinking::grimacing:)
I want to apply a filter on both my parent pages as my subpages for page selection but it only seems to be working on the parent page.


    label: Page
    type: pages
    multiple: false
    subpages: true
    image: icon
    query: kirby.collection('pages')
    link: false


return function($site)
    return $site->pages()->filter(function($page) {
        return $page->filterBy('template', '^=', 'page') || $page->template(['home', 'default', 'error']);

Other attempt for a collection

return function($site)
    return $site->pages()->filter(function($page) {
        return $page->filterBy('template', '^=', 'page') || $page->template(['home', 'default', 'error']);
    })->filter(function($child) {
        return $child->filterBy('template', '^=', 'page') || $child->template(['home', 'default', 'error']);

Unless ive missed what you are trying to do here, you can filter on multiple templates in the collection, and go through the whole site index…

$site->index()->filterBy('template', 'in', ['page', 'home', 'default', 'error');

Source: $pages->filterBy() | Kirby


return function ($site) {
    return $site->index()->filterBy('template', 'in', ['page', 'home', 'default', 'error')->sortBy('title');

If you do subpages: false this indeed works but if you do subpages: true then the filter only works on the first level.

For example. I have a subpage “this should not be here” with template “whatever”. When i filter on index with subpages: false I don’t see it, like expected.

query: site.index.filterBy('intendedTemplate', 'in', ['home', 'default'])

CleanShot 2021-02-07 at 01.34.38

But if I use that same query with subpages: true and I go to the subpage, I do see that page.

CleanShot 2021-02-07 at 01.36.23

CleanShot 2021-02-07 at 01.36.53

But I don’t want to see that page there. I only want everything with template home and default.

This cannot possibly work, because you cannot filter a page object.

Is there any other way to achieve this then? I was just trying everything I could think of to get some sort of filter on the subpages or am I trying to do something impossible and is the index one the way to go? (would be good UX to be able to work with the drilldown subpage functionality though)



No, this won’t work. The purpose of the subpages’ property is to control whether to show subpages of the queried selection or not. The alternative is a flat collection of filtered pages without drilldown.

Or a custom field…