Pages field query, but keep "stepped" UI

When you use the pages field; it shows a nice stepped UI that guides you to find the page you want bu walking over the folder structure.

How do I keep this when using a custom query to exclude certain pages? I tried query: site.index.filterBy('intendedTemplate', 'not in', ['some_template', 'some_other_template']), but that “flattens” the structure which is not user friendly for editors when there are lots of pages.

It’s probably due to the .index?
I’ve tried with site.pages.filterBy('intendedTemplate', 'not in', ['some_template', 'some_other_template']) too. That keeps the “steps”, but doesn’t do the filtering.

Yes, unless you remain on the same level, e.g. in a Starterkit

query: site.pages.filterBy('template', 'in', ['notes', 'photography'])

a query always flattens the list.

The reason why your example doesn’t do anything, is because your templates are probably not present on the first level pages (which is what site.pages returns).

Thx Sonja. Including the template of the page ‘on the first level’ makes those pages disappear (also in search).

A bit awkward, but it does work.