Filter pagelist by toggle field in pages

Hi,
I’m trying to wrap my head around the filtering of a pagelist based on toggle field in the pages to be filtered.

It seems that the list doesn’t like to be filtered. It’s not showing filtered pages, in fact it’s showing no page at all (screenprint below). I’ve also tried to use the same filter query for populating a select field dynamically with toggled pages but this also delivers empty (see my select field yml at the end).

My blueprints are stored in my plugin directory and I’m registering them within my plugin.
I’ve read in a post that sections are not filterable? Is this the case here? How to overcome this?

Below my filter function in my plugin as also my yml in the blueprint.
Any help is welcome, thanks in advance.

filter function in plugin:

    'pageMethods' => [
        'getAllActiveChildren' => function () {
            // Filter children where 'isactive' field is true
            $activeChildren = $this->children();
            error_log("Number of active children: " . $activeChildren->count());

            return $activeChildren;
        }

blueprint for pages section:


      - width: 1/3
        sections:
          activePages:
            type: pages
            headline: Active Pages
            status: all
            templates: [api, auth, cache] # List all the templates
            info: "{{ page.isactive }}"
            query: site.find('myplugins/myconfig').getAllActiveChildren


Trying to populate a select field with filtered pages:

              confgroups2:
                label: Category
                type: select
                options:
                  type: query
                  query: site.find('myplugins/myconfig').getAllActiveChildren
                  text: "{{ page.title }}"
                  value: "{{ page.id }}"

In image below: left unfiltered pages section, right: filtered (should show 2 entries):

The problem is the isActive() is a native Kirby Page method.

So instead of using filterBy, you would have to filter with a callback and check $page->content()->get('isActive').

See naming fields: Using fields | Kirby CMS

1 Like

Sonja, thanks again for helping me out. The new adjusted filter method below works perfect now:

    'pageMethods' => [
        'getAllActiveChildren' => function () {
            // Filter children where 'isactive' field in content is true
            return $this->childrenAndDrafts()->filter(function ($child) {
                return $child->content()->get('isactive')->toBool() === true;
            });
        }
    ],

Have a nice day :dizzy: