Query language text option not working

Hi,

I’m struggeling with my structure field.
In my Blueprint I have the following section:

relatedevents:
        type: fields
        fields:
          relatedevents:
            label: Related Events
            type: structure
            fields:
              event:
                label: Event
                type: select
                options:
                  type: query
                  query: site.children.find("program").children
                  text: "{{ page.title }}"

On my page I want the related page title like this:

<?php foreach($page->relatedEvents()->toStructure() as $event): ?>
  <a href="<?= $event->page()->toUrl() ?>">
    <button class="mt-4"><?= $event->event() ?></button>
  </a>
 <?php endforeach ?>

But in my text file it looks like this:

Relatedevents:

- 
  event: program/filmvorstellung

Every event.txt includes a Title: … and the panel looks just fine.

So what do I have to do to only get the page title for the event?

Thanks upfront!
Cheers
Alex

You have to convert the field value to a page object first, then get the title from that page object. What you show as text value for the select field in the Panel has no meaning for what you do in the frontent.

<?php foreach($page->relatedEvents()->toStructure() as $event): ?>
<?php if ($p = $event->event()->toPage(',')): ?>
  <a href="<?= $p->url() ?>">
    <button class="mt-4"><?= $p->title() ?></button>
  </a>
<?php endif ?>
 <?php endforeach ?>

A pages field is usually better suited for storing page relations: Pages | Kirby CMS

Thank you very much! That’s awesome! :tada: