I can’t figure out why Kirby stores the key instead of the values of a multiselect field.
This is my blueprint (based on the example in the docs):
service:
label: Service
type: multiselect
width: 1/2
options:
ser_interactive: Interactive
ser_print: Print
ser_motion: Motion
ser_visual: Visual identity
ser_strategy: Strategy
But the content stored is 'ser_interactive, ser_print'.
How do I store the values, or echo the values in my template? Using the code from the example in the docs echoes the keys.
<?php foreach ($page->categories()->split() as $category): ?>
<li><?= $category ?></li>
<?php endforeach ?>
-
You can’t store the values, unless you use your values as keys in your blueprint.
options:
"Interactive": Interactive
"Print": Print
# etc.
Edit: if this doesn’t work, there is the long version below.
2. You can get the values from the keys via the $page->blueprint() method.
3. You could alternatively store your key-value pairs in an array in your config and fetch via the options() helper.
Thanks for getting back so soon.
I ‘fixed’ it now like this, but it seems like a LOT of code for something that sounds so simple (let people select something from a list and display that):
<?= $page->blueprint()->field('industry')['options'][ $page->industry()->toString()]; ?>
As I said above, the easier way would be to build your options differently:
fields:
service:
type: multiselect
options:
- value:
text: Interactive
- value: Print
text: Print
- value: Some Option
text: Some Option
What I suggested in the first post, doesn’t seem to work, but this here does- that way you would store the values as desired and no need to get it from the blueprint.