How to filter to specific folder collection and a custom header field

Hello,

I can’t filter on both a folder and a custom header field (or even taxonomy).

Either it takes the taxonomy, or the folder, I’ve never been able to do both at the same time even though it’s in the same array.

  items:  {
            '@taxonomy':
              {
                'numdep': '03'
              },
            '@page': '/others'
          }

Also, I would like (unsuccessfully for the moment) to be able to filter on a custom header field without going through the taxonomy.

---
title: test title
taxonomy:
    numdep: '03'
    insee: '03102'
geocoding:
  lat: 1
  lng: 2
process:
  twig: true
location:
    insee: 34129
    numdep: 34
---

Is this possible? I’ve tried everything…

items: {
@page.header.location’:
{
‘numdep’: ‘34’
},
@page’: ‘/autres’
}

or

items: {
@page.header.location.numdep’: 34,
@page’: ‘/autres’
}

Thank you for the support

Finaly is possible with hooks…

public function onCollectionProcessed(Event $event)
{

    /** @var Collection $collection */
    $collection = $event['collection'];

    if ($infos = $this->isBarberDepartmentPage()) {

        $current_numdept = $infos['dept'];

        foreach ($collection as $item) {

            $numdept = $item->header()->location['numdep'];

            if (!empty($numdept) && $numdept != $current_numdept) {
                $collection->remove($item->path());
            }

        }
    }


}

But I find it’s not very efficient to have to browse through all our pages to finally delete some of them…

Hi @nicolasG ,

I also try to reduce my pages by filtering with onCollectionProcessed(Event $event) function.
Doesn’t the hook work in admin pages?

I give the reduced result back to $event['collection'] = $collection; but the list of pages in admins pages.html.twig stays the same.

Do I have to modify the twig in pages.html.twig, too? I thought the hook changes the collection.

 public function onCollectionProcessed(Event $event) {

    if ($this->isAdmin()) {

        $uri = $this->grav['uri'];

        if (isset($uri->paths()[1]) && $uri->paths()[1] === 'pages') {

            // $username = trim($this->grav['uri']->param('query'));

            /** @var Collection $collection */
            $collection = $event['collection'];

            $modify_user = 'just-for-test';

            foreach ($collection as $cpage) {

                if(!$cpage){
                    dump("An error has occured. Please contact site admin. No collection page found.");
                    continue;
                }
                $last_modified_by = property_exists($cpage->header(), 'draft') ? $cpage->header()->draft['last_modified_by'] : '';

                if ($last_modified_by !== $modify_user) {
                    $collection->remove($cpage);
                }
            }
            $event['collection'] = $collection;
        }
    }
}

Looking forward to your answer!

It’s not possible yet to filter custom page params.

I wrote an own filter regardless for my special needs of the admin filter using twig and blueprints in my own extension.