Hi there,
I have a structured field in site.yml that contains, for each entry, a name and a list of tags :
tagsGroup:
label: Ensembles de pratiques
type: structure
fields:
title:
label: Nom
type: text
tags:
label: Pratiques
type: tags
My ultimate goal is to create a set of checkboxes for each entry of the structured field.
If it’s not possible, I would at least like to make a set of checkboxes from all the tags of the structured fields.
The code below throws an error : Missing "text" definition in file: my-project/kirby/src/Form/OptionsQuery.php line: 99
fields:
tags:
label: Catégorie(s)
type: checkboxes
options: query
query:
fetch: site.tagsGroup.toStructure
text: {{ structureItem.tags }}
value: {{ structureItem.tags }}
Hm, your tags field contains a comma separated list of values so that doesn’t really make sense as a text or value of the checkboxes field.
Does it work if you use structureItem.title
for both text and value?
The code :
categories:
icon: circle-filled
sections:
categories:
type: fields
fields:
tags:
label: Catégorie(s)
type: checkboxes
options: query
query:
fetch: site.tagsGroup.toStructure
text: {{ structureItem.title }}
value: {{ structureItem.title }}
You have to put quotes around the curly braces
text: "{{ structureItem.title }}"
My mistake, sorry. Now it works for structureItem.title
.
No more error for structureItem.tags
but as you expected the tags are still grouped.
If you want to get all tags from all items in the structure, you can pluck all tags from the collection:
categories:
label: Catégorie(s)
type: checkboxes
options: query
query:
fetch: site.tagsGroup.toStructure.pluck('tags', ',', true)
1 Like
It works perfectly with query: site.tagsGroup.toStructure.pluck('tags', ',', true)
(instead of fetch:
). Thanks a lot for your help !
Is it possible to create a set of checkboxes for each entry of the structure field ?
No, that is not possible. It’s just flat checkboxes…
1 Like