Hi, I have created a blueprint and a template to categorise an exhibition on my web:
expotype:
label: Tipo
width: 1/3
type: radio
options:
individual:
es: Individual
en: Solo Exhibition
colectiva:
es: Colectiva
en: Collective
but in the panel, the options are displayed only in Spanish.
I have tried to render it in a template with this code:
<?php
$field = $expo->blueprint()->field('expotype');
$value = $expo->expotype()->value();
// multilang
echo $field['options'][$value][$kirby->language()->code()] ?? $value;
Because I want to show it only in listed children, but it not works. What’s wrong?
The options are shown in the selected user language, not in the translation language.
Alternative approach: Programmable blueprints | Kirby CMS
I don’t know, and the code snippet is missing details. What is $expo, a page object? Is the field used directly in the page, or within a structure, object, block?
When you
dump($field);
what do you get?
Thanks,
I understand the point, but create Programmable blueprints | Kirby CMS seems complicated. Maybe in the future…
dump($field);
display
Array
(
[label] => Tipo
[width] => 1/3
[type] => radio
[options] => Array
(
[individual] => Array
(
[es] => Individual
[en] => Solo Exhibition
)
[colectiva] => Array
(
[es] => Colectiva
[en] => Collective
)
)
[name] => expotype
)
How can I show the correct one for each case?
This should actually work…
Try hardcoded:
echo `echo $field['options']['individual']['en'] ?? $value;
For some strange reason, after dump the $value instead of the $field the code works:
<?php
$field = $expo->blueprint()->field('expotype');
$value = $expo->expotype()->value(); ?>
<p class="expo-type"><?php echo $field['options'][$value][$kirby->language()->code()] ?? $value; ?></p>