Blueprint - pages field - filter by template

I’m trying to write a Blueprint. I have a pages field to allow the editor to select a page. Rather than display all the pages in the website, I’d like to just display/list the pages that use a particular template. Here’s my code, but the pop-up window says “No pages to select”.

title: Project Blueprint

fields:
	produces:
		label: Linked product
		type: pages
		query: site.pages.template('product-template')

Is this something to do with child pages? I’ll try and explain the structure:

Parent page PROJECTS has PROJECT subpages. There is also a PRODUCTS parent page with PRODUCT subpages (that use the product-template template). I need to link project pages with the relevant product pages.

Don’t know why but this works:

query: site.index.template('product-template')

Because this queries all pages of the site, which is not such a good idea (not such a big problem with small sites, but the more pages you have, the worse the performance). Better to use

query: kirby.page('products').children

query: site.children.listed.template('product-template')

You can also use this. With the two differences that only published children pages can be selected and no pages from the top level.

This will query only pages of the first level, not the children of the products page.

1 Like

Our answers have overlapped :sweat_smile:
What is the disadvantage of my version?

/content
  page-1 // this level will be queried by site.children
    subpage-1 // this level will not be included in site.children
  page-2
    subpage-of-two.
1 Like

This works, but I now get the arrows in the pop-up, as if there are children of these pages (there aren’t). Is there a way not to show the arrows?

This doesn’t work:

query: kirby.page('products').child

This seems to work, but is it a little verbose?

query: kirby.page('products').children
subpages: false

But if there are no subpages, those arrows are disabled anyway?

But yes, to get rid of the arrows, setting subpages: false is the way to go.