Fetch tags as options from another tags field inside a blueprint

Hey Kirby,
I’m still trying to wrap my head around the new Fetch functionality inside Blueprints.
Like here.
I set up a tag field inside my site.yml that should define wich tags can be used in other blueprints.
When i then insert the code from the link above inside my other blueprints:

tags:
  label: Tags
  type: tags
  accept: options
  options: query
  query:
    fetch: site.tags.toStructure.sortBy("name", "asc")
    text: "{{ structureItem.name }}"
    value: "{{ structureItem.value }}"

I get this error inside the panel:

Argument 1 passed to Kirby\Cms\StructureObject::setContent() must be of the type array or null, string given, called in /homepages/40/d231701815/htdocs/urbantypes/kirby/src/Toolkit/Properties.php on line 130

Wich makes sense I guess, because the tag content is already an Array. But when I rewrite the blueprint to just fetch: site.tags it gives me an Invalid query result data error. What kind of data should be fetched by the query?

Usually toStructure is used for structure fields, but the example in the docs aren’t clear to me here.

I use a tag field to define options for a select field (slightly different use case) and it works with this query:

query:
    fetch: site.tags.split

This might also be valid for tag options?!

1 Like

Hah! Of all the Methods, split wasn’t the one I tried. Thank you it works just fine now.

So I still wonder to what the structure field refers in the example, because it is declared to be tags :thinking:

I think it refers to a structure field in site.yml with two fields named value and title.

The examples for the select field options are less confusing.

Yes, @flokosiol is right, in the example, a structure field is used to define the possible tags, not a tags field, hence the toStructure method in the query (the example code was based on an older Starterkit example). Might be a confusing that the field is also called tags and we could be more explicit about what we are referring to… Still work in progress. I added a note in the docs repo to add more explanations.