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.

Blueprint

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

Collection

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

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']);
    })->sortBy('title');
};

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

<?php

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)

Cheers!

Sam

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ā€¦