Tags field: query options from other pages values

I had the following tags field in Kirby 2:

  tags:
    label: Tags
    type: tags
    lower: true
    index: all

It used to allow me to have autocompletion from the tags used on other pages. I’m trying to redo the same in Kirby 3 with the query language but cannot figure out the right syntax.

The ideal would be to autocomplete only with the tags of the other articles. I tried something like:

  tags:
    label: Tags
    type: tags
    options: query
    query:
      fetch: site.find('blog').children.filterBy('template', 'article').pluck('tags')

But the panel throws errors: Missing "text" definition and then Missing "value" definition once text is defined.

I didn’t find any help about using query to get fields values in the docs. Anybody knows what I should put as text and value for queries on field values?

This should do it:

    text: "{{ arrayItem.value }}"
    value: "{{ arrayItem.value.slug }}"

Sadly this doesn’t seems to be the right values. If I inspect the Panel field options, I can see some but all the text/value are empty:

Oh, I got something with item instead of arrayItem. However it returns the whole list of tags for an article and not each separately (for example: focus, iteration, adjust, adapt, commitment).

I tried to change the query to split the values with:

fetch: site.find('blog').children.filterBy('template', 'article').pluck('tags', ',')

but now I get a different error: explode(): Empty delimiter.

Yes, I get the same, it works with normal template code, but not in the query language, hm.

Ah, it works if you use double quotes instead of single quotes:

fetch: site.find('blog').children.filterBy('template', 'article').pluck("tags", ",")

Sounds like a good idea to use double quotes in query language, this is the second issue that can be solved like this.

Oh boi, how weird. Thanks, it works now with your initial suggestion, aka arrayItem. Here’s the final solution for whoever might be interested:

  tags:
    label: Tags
    type: tags
    options: query
    query:
      fetch: site.find("blog").children.filterBy("template", "article").pluck("tags", ",", true)
      text: "{{ arrayItem.value }}"
      value: "{{ arrayItem.value.slug }}"
1 Like

Coming from v2 I was also looking for a way to recreate the behavior I was used to. Thank you for finding it!