In my blueprint I have a pull-down that show all available pages on my site;
button_anchor:
label: Button - Anchor
type: select
options: pages
But how can I fetch / query (in my template) the full URL that belongs to the chosen page in that pull-down list?
<?php echo $page->button_anchor(); ?>
This code returns the basic slug, not the full URL…
I’ve tried these options, but whatever I do - I still get the basic slug;
- edit - I need the full URL so I can create a link to that page;
<button onclick="location.href=#">click</button>
Where # should be the anchor, fetched from the pull-down…
What does it say when you dump button_anchor() ?
From what I’ve read in the docs, with the pages option, you’ll get a page URI, so you can build the URL like this (not tested it tho ):
<?php
echo $site->page($page->button_anchor())->url()
?>
1 Like
LCD344
3
I think you can do something like that in your template file
url($page->button_anchor());
1 Like
Both work - I choose the shortest one, thanks!
The “chaining” queries of Kirby can sometimes be really difficult for me
I believe there is also:
$page->button_anchor()->toPage()->url()
You may need to wrap this in a protective if
to make sure you don’t call the url
method on null.
1 Like