Working with Multiselect in my Template

Good evening,

I’m using multiselect in a blueprint to assign different categories to projects in my portfolio.

category:
    type: multiselect
    options:
        photography: Photography
        graphicDesign: Graphic Design
        userInterface: User Interface
        typeDesign: Type Design

In a Template I am using these values at different positions. How is it possible (using “Graphic Design” as an example) to sometimes insert “graphicDesign” and sometimes “Graphic Design”?

Thank you,
Simon

Well, when you just call the field, you will always get the stored value.

To get the “label”, you have different options:

  1. In a multilanguage site, use the translations array to store key-value pairs you can then retrieve via the t() helper.
  2. Read the value from the blueprint, Using blueprints in the frontend | Kirby CMS
  3. Use a category map (similar to option 1) you define in your config file (see, Sort collection by translated value from category map - #3 by jonabaptistella, example uses Kirby 2 syntax which you would have to adapt to Kirby 3, but you get the idea)

Can you give an example how I would insert a value from my blueprint using your second option?

<?php
// get the available options from the blueprint
$options = $page->blueprint()->field('category')['options'];
dump($options);

// when looping through the stored values, fetch the option with the key from the options array
foreach($page->category()->split(',') as $category) {
  echo $options[$category] ?? $category;

}