# Querying tags from a structured field in another field (checkboxes)?

**URL:** <https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 20, 2021, 11:52am UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994 "2021-04-20T11:52:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrieng](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/adrieng/32/14454_2.png) [@Adrieng](https://forum.getkirby.com/u/Adrieng)\
**Post date:** [April 20, 2021, 11:52am UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/1 "2021-04-20T11:52:59Z")

</div>

Hi there,

I have a structured field in site.yml that contains, for each entry, a name and a list of tags :

```auto
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`

```auto
fields:
      tags:
        label: Catégorie(s)
        type: checkboxes
        options: query
        query: 
          fetch: site.tagsGroup.toStructure
          text: {{ structureItem.tags }}
          value: {{ structureItem.tags }}

```

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [April 20, 2021, 12:01pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/2 "2021-04-20T12:01:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Adrieng](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/adrieng/32/14454_2.png) [@Adrieng](https://forum.getkirby.com/u/Adrieng)\
**Post date:** [April 20, 2021, 12:04pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/3 "2021-04-20T12:04:03Z")

</div>

Same error :

 ![Capture d’écran 2021-04-20 à 14.03.39](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/4/4a99ebc556a840bcd5358ad661e1dfea8637dd9b.png)

---

<div class="post-metadata">

**Author:** ![Adrieng](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/adrieng/32/14454_2.png) [@Adrieng](https://forum.getkirby.com/u/Adrieng)\
**Post date:** [April 20, 2021, 12:04pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/4 "2021-04-20T12:04:59Z")

</div>

The code :

```auto
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 }}

```

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [April 20, 2021, 12:12pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/5 "2021-04-20T12:12:16Z")

</div>

You have to put quotes around the curly braces

```auto
text: "{{ structureItem.title }}"

```

---

<div class="post-metadata">

**Author:** ![Adrieng](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/adrieng/32/14454_2.png) [@Adrieng](https://forum.getkirby.com/u/Adrieng)\
**Post date:** [April 20, 2021, 12:24pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/6 "2021-04-20T12:24:31Z")

</div>

My mistake, sorry. Now it works for `structureItem.title`.  
No more error for `structureItem.tags` but as you expected the tags are still grouped.

 ![Capture d’écran 2021-04-20 à 14.24.01](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/f/fd99e59532ac769c4719f4ea5fd34e7fe9f5c5ec.png)  
 ![Capture d’écran 2021-04-20 à 14.23.31](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/c/c8f6c3f58defd2c83414b94dedf9ca57a85b7a45.png)

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [April 20, 2021, 12:34pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/7 "2021-04-20T12:34:27Z")

</div>

If you want to get all tags from all items in the structure, you can pluck all tags from the collection:

```auto
   categories:
        label: Catégorie(s)
        type: checkboxes
        options: query
        query:
          fetch: site.tagsGroup.toStructure.pluck('tags', ',', true)

```

---

<div class="post-metadata">

**Author:** ![Adrieng](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/adrieng/32/14454_2.png) [@Adrieng](https://forum.getkirby.com/u/Adrieng)\
**Post date:** [April 20, 2021, 12:41pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/8 "2021-04-20T12:41:26Z")

</div>

> [@pixelijn](#):
>
> `site.tagsGroup.toStructure.pluck('tags', ',', true)`

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 ?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 20, 2021, 5:40pm UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/9 "2021-04-20T17:40:01Z")

</div>

> [@Adrieng](#):
>
> 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…

---

<div class="post-metadata">

**Author:** ![Adrieng](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/adrieng/32/14454_2.png) [@Adrieng](https://forum.getkirby.com/u/Adrieng)\
**Post date:** [April 21, 2021, 9:32am UTC](https://forum.getkirby.com/t/querying-tags-from-a-structured-field-in-another-field-checkboxes/21994/10 "2021-04-21T09:32:24Z")

</div>

Ok, thank you @texnixe.
