Is it possible to concatenate multiple config options to display in one blueprint field?
I have the options mainCountries
and moreCountries
in my config, as I need to be able to display them separately.
In a blueprint, I now need to show them as options of one select
field.
Is that feasible?
The following example doesn’t work, obviously, but is shown to illustrate the question:
country:
type: select
options:
type: query
query: [ kirby.option('mainCountries'), kirby.option('moreCountries') ]
text: "{{ item.value }}"
value: "{{ item.key }}"
I’d create a custom method that returns all values from those config options.
Many thanks for pointing me in the right direction, Sonja.
Worked like a charm.
For anyone wondering about the same or a similar thing, here’s the/my solution:
Create a new site method as descripted in the docs.
Put this in your method’s/plugin’s index.php
:
<?php
Kirby::plugin('YOURMONICKER/YOURPLUGINNAME', [
'siteMethods' => [
'YOURMETHODNAME' => function ($options) {
$return = [];
foreach ($options as $option):
$items = option($option);
foreach ($items as $key => $value):
$return[$key] = $value;
endforeach;
endforeach;
return $return;
}
]
]);
In your blueprint use it like this:
fieldID:
type: select
options:
type: query
query: site.YOURMETHODNAME([ 'oneOption', 'anotherOption' ])
text: "{{ item.value }}"
value: "{{ item.key }}"