How to print "query" field url

I would like to have a field, that would allow to link to other site pages, so I created this:

    label: Button link
    type: pages
    query: site.index

And in template added code:

<a href="<?= $site->url() ?>/<?= $section->buttonlink() ?>"> some text </a>

But on page I get something like this:

-%20 - or more code is added.

The pages field stores its content in yaml format:


- mypage

To fetch content from that field, you can use the toPage() (for a single page) or the toPages() (for multiple pages) methods

Your code then would look like this:

<?php if($p = $section->buttonlink()->toPage()): ?>
<a href="<?= $p->url() ?>"><?= $p->title() ?></a>
<?php endif ?>

Thank you very much, now all is working fine.