Fetching field multiselect text not value in panel

Hi,

I’m sure there is an easy way to do that, but so far, no luck. What I’m trying to do is to get the text from my multiselect field on my panel, more precisely, to show this text in the info field from its parent page.

In the parent page, this is what I have, I tried to convert the query langage from PHP to the one for YAML… doesn’t work:

type: pages
headline: Profiles
info: "{{ page.blueprint.field('major')['options'][page.major.value]['en'] }}"

The child’s page, the multiselect field is like that:

major:
    label:
      fr: Formation initiale
      en: Initial major
    type: multiselect
    options:
      directing:
        fr: BA. Réalisation
        en: BA. Film Directing
      editing:
        fr: BA. Montage
        en: BA. Editing
      sound:
        fr: BA. Son
        en: BA. Sound 

As you can see, there is two languages as well. Any ideas?

Set up a method in a page model for the child pages that returns the value you need, you cannot do such complex array index stuff in query language.

1 Like

That completely makes sense, somehow I forgot the page model extension! I love Kirby. Will post the solution here once I’m done.

So in case anyone needs it:

<?php
class ProfilPage extends Page
{
  public function diploma()
  {
    $field = $this->blueprint()->field('major');
    $value = $this->major()->value();

    // multilang
    return $field['options'][$value][kirby()->language()->code()];
  }
}

Better check if your array keys exist:

 return $field['options'][$value][kirby()->language()->code()] ?? '';
1 Like

Good point. Thank you for the input!