Populate select field with programatically created structure

good morning everyone,

today I have a question regarding structures. i want to populate a select field for “age”, so lets say from 10 to 80 years. this field will be used in the panel but also in the frontend. right now the field where i store the value looks like this:

          age:
            type: select
            width: 1/3
            label: Alter
            options: query
            query: page.populateNumeric

now i obviously have to create the function populateNumeric in my page model so the query can find the values. for this i have created a pagemodel which contains, besides some other functionalities, my populateNumeric function

class JDSPage extends Page
{
    public function populateNumeric(int $start = 1, int $end = 99, $invert = false)
    {
        $_structure = new Kirby\Cms\Structure();
        $props = [];

        if (site()->age_start()->isNotEmpty())
            $start = site()->age_start()->value();

        if (site()->age_end()->isNotEmpty())
            $end = site()->age_end()->value();

        for ($i = 0; $i <= ($end - $start); $i++) {
            $_structure->add(new Kirby\Cms\StructureObject([
                'id'        => $i,
                'content'   => ['desc' => strval($start + $i)]
            ]));
        }

        if ($invert)
            $_structure = $_structure->flip();

        return $_structure;
    }
}

for the starting and ending numeric values of the ages i use values stored in site. i first create a structure, then i create the structureobjects and here is where i am having trouble. in a snippet i want to be able to call $structureobjectItem->desc() so i define 'desc' => strval($start + $i) in the content array for each structureObject.

frontend
here i populate the input select in a snippet like this

<option <?= e($option->id() == $value, 'selected', '') ?> value="<?= $option->id() ?>"> <?= $option->desc() ?></option>

which results in this
Bildschirmfoto 2022-09-29 um 10.13.05

so it seems to be working fine.

panel
but in the panel i am getting empty options. the correct amount of options are there, but the values are just not being read.


Bildschirmfoto 2022-09-29 um 10.15.30

does someone have an idea what i am doing wrong?

thank you!

I just got enlightend and figured it out :slight_smile: my yaml was of course wrong… it has to look like this:

query:
              fetch: page.populateNumeric
              text: "{{ structureItem.desc }}"
              value: "{{ structureItem.id }}"