Query subset of Pages

Iā€™ve tried to look at the other similar questions but canā€™t seem to get a query that works.

In my site.yml Iā€™ve got a ā€˜pagesā€™ field type displaying all child pages:

pages:
  type: pages
  label: Pages

This works fine, but Iā€™d like to reduce this to a particular subset of pages. If I wanted to show ā€˜homeā€™, ā€˜aboutā€™ and ā€˜errorā€™, how could I assemble this query? I expected this to work:

pages:
  type: pages
  label: Pages
  query: site.index.filterBy("template", "in", ["about", "Error", "Home"])

I also tried every other combination and version I could think of, including suggestions from other similar forum questions, but it always shows all child pages.

query: site.template("about")
query: site.template('about')
query: site.children.filterBy("template", "about")
query: site.children.filterBy("template", 'about')
query: site.index.filterBy("template", "in", ["About", "error", "home"])

I also tried using with:

pages:
  type: pages
  label: Pages
  options: query
  query: **tried everything here**

Hm, this first one should actually work. What Kirby version are you using?

Thanks, @texnixe. I thought it should work too. I am using Kirby 3.2.2.

Could it be to do with the quotation marks? i.e. " vs ' ? I saw this forum post where type of quotes seems to matter: Query language query

No, your double quotes are perfect. I tested in my install (currently 3.2.4-rc1) and it worked, but should work since 3.2.0.

Iā€™ve got a similar issue in my site.yml blueprint.

I try to query subpages filtered by template pages in different pages section like this :wink:

title: Site

tabs:

  # deals tab
  deals:
    label: Deals
    icon: layers
    columns:

      # prospect
      prospect:
        width: 1/3
        sections:

          # a list of subpages
          prospects:
            type: pages
            headline: Prospects
            query: site.index.filterBy('template','deal_prospect')


      # contact
      contact:
        width: 1/3
        sections:

          # a list of subpages
          contacts:
            type: pages
            headline: Contacts
            query: site.index.filterBy('template','deal_contact')
...

but each pages sections return the first level of pages.

I use Kirby 3.3.3

@gillesvauvarin Sections do not have a query option, only a single parent.

To filter your sections, you need a plugin (Pagesdisplay section), but then you loose the option to add new pages.

It is possible to extend this plugin by re-enabling the add method (and only create pages in a given parent).

Ok, thanks Sonja, remember that now. I stayed away from the code for few weeks (little baby canā€™t wait) and already forget Kirby rules like this.

I will use the plugin.

Yes, little ones need a lot of love and attention :hugs:

Mhmm ! :thinking:

Did this with the plugin but return nothing ā€¦

title: Site

tabs:

  # deals tab
  deals:
    label: Deals
    icon: layers
    columns:

      # prospect
      prospect:
        width: 1/3
        sections:

          # a list of subpages
          prospects:
            type: pagesdisplay
            headline: Prospects
            query: site.index.filterBy('template','deal_prospect')


      # contact
      contact:
        width: 1/3
        sections:

          # a list of subpages
          contacts:
            type: pagesdisplay
            headline: Contacts
            query: site.index.filterBy('template','deal_contact')

....

Do these templates actually exist?

Yes, corresponding php template files are created in the templates folder but with no code inside.
You can check in my Zip, see the link below.

site.index(true).filterBy('template','deal_contact')

I forgot to set the index parameter to ā€œtrueā€ to get drafts pages :-/
Works now!