Blueprint pages field - query from multiselect array

Hi all!

Having an issue here trying to query which Project Pages pages can be added to my Work Category pages based on multiselect values…

In my example, I have two Work Category pages “Brand” and “Animation”. In my Project Page, I have a multiselect field that populates both Work Category pages by their titles. Here is the multiselect field in my project.yml blueprint:

selectCategory:
  type: multiselect
  label: Work Category
  options: query
  placeholder: All Work
  query:
    fetch: site.childrenAndDrafts.filterBy('intendedTemplate', 'work-category')
    text: "{{ page.title }}"
    value: "{{ page.title }}"

Here is the pages field in my work-category.yml blueprint:

categoryPages:
  type: pages
  label: Published
  options: query
  query: site.find('work').children.listed.filterBy(page.title, 'in', Selectcategory.split(',')) // This is what I'm having trouble with...

In my Project Page, this project.txt file has the following:

Title: Project Name

----

Selectcategory: Brand, Animation

How can I have the page query above in the blueprint show this page on both “Brand” and “Animation” work category pages? When I click the Add + in my panel to add a page to Brand or Animation, I get the following error:

Your query must return a set of pages

Hope I provided enough insight and clarification as to what I’m trying to achieve here, ha.

Thank you all for your help! :slight_smile:

Hm, that seems strange. To pick something from a field, you would have to pass the page to pick from, e.g. kirby.page('somepage').selectCategory.split()- but here it is not clear what page to query?

Hi @pixelijn, thanks for the reply!

I have the page query working, I’m just trying to turn my multiselect values into an array.

If I keep limit my multiselect to one (multiple: false) it works, but I can then only add a page to one page instead of both…

selectCategory:
  type: multiselect
  label: Work Category
  options: query
  placeholder: All Work
  max: 1
  multiple: false
  query:
    fetch: site.childrenAndDrafts.filterBy('intendedTemplate', 'work-category')
    text: "{{ page.title }}"
    value: "{{ page.title }}"

And this query works just fine as it is filtering by a single match, no array matching values:

categoryPages:
  type: pages
  label: Published
  options: query
  query: site.find('work').children.listed.filterBy('Selectcategory', page.title)

And the project.txt is now:

Title: Project Name

----

Selectcategory: Brand

So, using this example above I can select “Brand” from the multislect in a Project page and now add this to my Work Category page. So now that the above works, I’m trying to figure out how to query if the page.title (“Brand” and/or “Animation”). How can the query filter from the multiselect values instead of the single value?

One item (no array of options, just the single string value here works great):
query: site.find('work').children.listed.filterBy('Selectcategory', page.title)

But I am trying to split my values (“Brand, Animation”):
query: site.find('work').children.listed.filterBy(page.title, 'in', Selectcategory.split(','))

Hopefully this additional info helps! Thanks!

You still want to filter by the selectcategory, not the title, therefore you have to pass the third parameter instead

  query: site.find('work').children.listed.filterBy('Selectcategory', page.title, ',')

Incredible!! That was the trick.

Thanks @pixelijn :sunglasses: