Using labels (rather than values) of Panel multiselect field options in the front-end

Hi,

I’m currently building out a project page for a client that is structured similarly to a blog post, with each post attributed to multiple contributors.

From the panel, my client can select each contributor using a multiselect field set up with the following query:

contributors:
            label: Contributors
            type: multiselect
            options: query
            query: site.find("people").children

This populates the multiselect field with the full names of each possible contributors to select from. However, when I use the following query…

<?php foreach($page->contributors()->split(',') as $contributor): ?>
<li><?= $contributor ?></li>
<?php endforeach ?>

…to fetch the contributors of each project on the project page, it returns the results in a not-human-friendly format: “people/joe”, “people/jane”, etc.

Is there a Kirby helper / method of some kind that allows me to use the labels seen when selecting from the options in the multiselect field, rather than the value that is currently being returned?

Thanks!

Since your values are supposed to be pages, convert the values to a pages collection:

<?php foreach($page->contributors()->toPages(',') as $contributor): ?>
<li><?= $contributor->title() ?></li>
<?php endforeach ?>

Instead of a multiselect field, you could use a pages field (in that field, you would use toPages() without the comma as argument in your template.

2 Likes

This worked for me, and I’ve taken your suggestion regarding the field itself. Thank you! :slight_smile: