Select displays as a slug in template

I am new to this, so forgive my naiveté.

I have a select in my .yml like this:

designer:
  label: Designer
  type: select
  options: query
  query:       
    template: designer
    fetch: pages
    width: 1/2

[ ↑ i don’t know why my indents aren’t showing up properly on this forum]
But when I display it in my template with this:
<p>by <?= $page->designer() ?></p>

it displays as “first-last” all lowercase with hyphens. I’d like it to display as First Last, as it appears in the select on my panel.

Any help would be much appreaciated!

If you don’t define what is stored in your content file, Kirby stores the UID of the page, not the title. You can either store the title in the content file by setting the corresponding option in your blueprint:

designer:
  label: Designer
  type: select
  options: query
  query:       
    template: designer
    fetch: pages
    value: '{{title}}'
    width: 1/2

Or you can store the URI of the page, then get the page object from that information

designer:
  label: Designer
  type: select
  options: query
  query:       
    template: designer
    fetch: pages
    value: '{{uri}}'
    width: 1/2

Then get the title in your template like this:

// convert URI to page object and check if the page exists
if($p = $page->designer()->toPage()):
  echo $p->title();
endif;

The best option depends on whether all you need is just the value of the select or if you need any other information from that designer page as well, for example, if you want to get the designer’s image from that page.

Oh, and as regards the indentation, when posting blocks of code, use three backticks on a separate line before and after your code block.

1 Like

Yes! You rule, thank you for the help!

I tried to save the title, but that didn’t work. The URI solution is perfect!