Kirby-pagetable plugin -> show key/value of select field

Hi all,

i was wondering how to add the value of a select field as value for my pagetable field?
It is maybe not possible cause the select field stores key or value but not both.

Any idea how i can store the key but show the value of a select field?

text: '{{ page.category }}'

KR

What is stored in that select field?

Hi,
the key. I have key value pairs:

text: "{{ structureItem.text  }}"
value: "{{ structureItem.key }}"

Ok, I wanted the information that you are referring to a structure field.

Try:

text: "{{ kirby.page('somepage').nameOfStructureField.toStructure.findBy('key', page.category).text }}"

Worth a try…no guarantee.

nice try but it does not work ;).

Then try with a custom page method.

i tried with a custom fieldMethod but i don’t know how to get the value within the php.
The question is now: how to get this value with the key in my custom fieldMethod.

thx alot!

i think i can get it :wink: …something like this:

page(‘mypage’)->field()->findBy…

got it:

page(‘mypage’)->field()->toStructure()->findBy(‘key’, $value)->text()

thx alot!

   Kirby::plugin('your/plugin', [
    'fieldMethods' => [
        'toValue' => function($field) {
          $value = $field->value;
          return '<span class="category-label" data-category="'. $value .'">' . page('mypage')->field()->toStructure()->findBy('key', $value)->text() . '</span>';
        },
    ]
]);