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**
simon-hayden:
pages: type: pages label: Pages query: site.index.filterBy(ātemplateā, āinā, [āaboutā, āerrorā, āhomeā])
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
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
texnixe
February 14, 2020, 5:58pm
6
@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.
texnixe
February 14, 2020, 6:07pm
8
gillesvauvarin:
little baby canāt wait
Yes, little ones need a lot of love and attention
Mhmm !
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')
....
texnixe
February 14, 2020, 7:05pm
10
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!