Issues filtering page by template on blueprint

Hello! I’m setting up related pages on my blueprint, that use the same template. I’ve been following the instructions from here to retrieve pages with a specific template, but the query results in empty results when using the panel.

The template is “guideline”:

query: page.index.filterBy('template', 'in', ['guideline'])

I know in general the template is fine because I’m also using it on the homepage template and it’s working:

<?php $items = $pages->template('guideline'); if($items and $items->isNotEmpty()):?>

But in the blueprint case, I’m not sure what’s the problem. Ideally I’d also hide the current page from the options, but now nothing is showing.

This is the full example in case anything else is interfering with this (I don’t think so, since removing the query does list all pages.)

  sidebar:
    width: 1/3
    sections:
      metadata:
        type: fields
        fields:
          longTitle:
            label: Long title
            type: text
            buttons: false
          summary:
            type: textarea
            maxlength: 1000
            buttons: false
          featured:
            label: Image preview
            type: files
            uploads:
              template: image
              layout: cards
              image:
                cover: true
          related:
            label: Related Pages
            type: pages
            query: page.index.filterBy('template', 'in', ['guideline'])
      gallery:
        type: files
        template: image

But I’m unsure where my mistake is.

page.index refers to the subpage tree of the current page. In your template example above

however, you are querying first level pages.

On a sidenote, if you don’t want to filter by multiple template, you can just use

site.pages.template('sometemplate')

Thanks for the answer. At the moment I’d like to filter pages that use only one specific template. I’m adding the query on the blueprint “guideline”, and from there I’d like to be able to pick related pages that use the “guideline” template.

I don’t think I understand your example, because using in the blueprint:
kirby.pages.template('guideline')

Returns in the panel:
Your query must return a set of pages

Could it be because the pages are in different folders inside the site?

The information I’m missing is where these pages are in relation to the current page? Sibling pages?

Should have been site.pages instead of kirby.pages

1 Like

Thanks again, and I’m sorry for not clarifying about siblings / children / … Thanks to your explanation I’ve been able to solve it and also learned a few things along the way, while checking the docs too. With your latest example works :slight_smile: