Query that plucks tags from Structure field

I have a tag field inside a structure field. I’d like to autocomplete this field by querying all of the other pages. I’ve done this successfully many times with tags, but never from inside a structure field.

    type: structure
            type: tags
            options: query
            query: page.parent.childrenAndDrafts.pluck("kiez", ",", true)
            max: 1

This does not work. How do I get the query to look inside the structure field?

I think you need a custom method to achieve this, pluck only works with single value fields or fields with comma etc. separated values.

I tried calling a custom site method which returns an array, but that didn’t work. like query: site.getItems where getItems basically is like:

$array = $this->someField()->yaml();
return A::pluck($array, ‚tags‘);

(Strange apostrophes due to me typing on iOS)

Did it much like you described here

That should actually work, what is your Kirby version? And what’s in your blueprint?

Well, oddly it does now … Guess it was restarting PHP that must’ve worked :confused:

Hi there - thanks for this helpful start! I’m trying to achieve something similar but am struggling to implement.

I have a template called review with a structured field exhibitions. One of the yaml fields in the exhibitions structure is venue.

I would like a custom method that plucks all the values from exhibitions()->toStructure()->venue() of each page on the site using the review template.

How would I implement the above with e.g., the following custom site method:


Kirby::plugin('lettau/custom-site-methods', [
    'siteMethods' => [
        'venues' => function () {
            //  custom site method goes here ?

Solved like this (could be more elegant!):


Kirby::plugin('lettau/custom-site-methods', [
    'siteMethods' => [
        'venues' => function () {
            //  custom site method goes here
            $site = kirby()->site();
            $array = [];
            $reviews = $site->find('reviews')->children()->listed()->flip();

            // exhibitions yaml
            foreach ($reviews as $review) {
                $exhibitions = $review->exhibitions()->yaml();
                $venues = A::pluck($exhibitions, 'venue');
                $list = implode(', ', $venues);
                array_push($array, $list);

            $array = array_filter($array);
            $array = implode(', ', $array);
            $array = explode(', ', $array);
            $array = array_unique($array);

            return $array;

See this thread how to collect these items into a structure instead: Difficulty merging structures into a collection - #11 by texnixe

Much better - thanks!