How to output the real text instead of the value of a subpage?

Hi
My content folderstructure is:

dishes
  vorspeisen
    salat
    suppe_kuerbis
  hauptspeisen
    schnitzel_vom_rind
    fisch_von_der_dorade
    ...

In my blueprint for dish (salat, suppe_kuerbis, schnitzel_vom_rind, …) is:

tags:
    label: Tags
    type: checkboxes
    options:
      vegetarisch: Vegetarisch
      fuerKinder: Für Kinder
      ...

On the frontpage I wanna output the real text of the tag instead its value.
I iterates through all “dishcategories” (vorspeisen, hauptspeisen, …) like this:

<?php foreach ($page->children() as $category): ?>
...

In each “dishcategory” I iterate through all dishes like this:

<?php foreach ($category->children()->listed() as $item): ?>
...

To output the tags of the subpage(s) I use this:
<?= $item->tags() ?>

But it results in for example “fuerKinder” instead of “Für Kinder”.

I tried to access the blueprint of the subpage like this:
(found it in the documentation here)

$field = $page->blueprint()->field('tags');
$value = $page->tags()->value();
                    
dump($field['options'][$value] ?? $value);

But the dump is empty.

What do I do wrong?

Kind regards
Alain

Your code will only work if your checkboxes field contains a single value. But since the field stores multiple values and these as a comma separated string, you would have to create an array from the tags, then loop through the tags:

$field = $page->blueprint()->field('tags');
$tags = $page->tags()->split(',');
foreach ($tags as $tag) {
  echo $field['options'][$tag] ?? $tag;
}

Or, if you want to output the original comma separated list:

$field = $page->blueprint()->field('tags');
$tags = $page->tags()->split(',');
$tags = array_map( function( $tag ) use( $field ) {
    return $tag = $field['options'][$tag] ?? $tag;
}, $tags );

echo implode(', ', $tags);

Great, it works :smiley:
Thanks alot!
I am amazed how quickly you answer outside of office hours.

What’s that :wink: ?