How to get a URL from a subpage

Hey there.
Maybe it sounds stupid, but i am still exploring Kirby.
I didn’t find anything in the cookbook and in my desperate i tried lots of solutions from diffent problems but it never helped.

I simply want to creat a link to a subpage with an anchor. I guess i have to get the URL from the Tamplet (that by the way it not visible in the menu, couse it is just the legal notice) and place it in the “href”.
But how do i do that?

You can get any page with the page helper:

if($p = page('path-to-page')) {
  echo $p->url();

Note that you have to pass the complete path (for example, a subfolder in the projects page: page('projects/project-a').

If that doesn’t help, please provide your code snippet.

ok, i see what you are doing, but i don’t know how i have to implent it in my code.
here is my try:

<footer class="footer">

<?= if($p = page('content/0_legal_notice')) {
  echo $p->url();
<a class="footer_link footer_link_1" href="<?= $p->url() ?>">Legal notice</a>
<!-- <a class="footer_link footer_link_2" href="/privacy.php">Privacy statment</a> -->
<a class="badass_small" href="<?= url() ?>">&copy; <?= date('Y') ?> / <?= $site->title() ?></a>

Do not include the prepended number and the content folder, it is not part of the path:

<?php if($p = page('legal_notice')) {
  echo $p->url();

Mh, seems to be a syntax error. Sry i am realy not a php guy :smiley:


Oh, I copied your code including the error, should of course be

<?php if($p = page('legal_notice')) {
  echo $p->url();

Ok no error anymore, but is likes me to the error page.
Guess it has to do something with how i put the url in the href.

<?php if($p = page('legal_notice')): ?>
  <a class="footer_link footer_link_1" href="<?= $p->url() ?>">Legal notice</a>
<?php endif ?>

I am feeling we are getting closer, still the error page. Just to be shure here my is the structure of my data:

From the structure it looks as if you are using Kirby 3 but the category is Kirby 2?

What is the error message you get?

Please do a


Do you get an error or are you redirected to the error page when you click the link?

If the code is alright and you are redirected to the error page, check if the generated URL looks alright and if so, check if links to other pages are working.

Sry. was not shure which one i downloaded. I will change it.

sry. I dont know where i supposed to do that.

It is the error page.

It is a onepager. just the data privacy and legal notice is supposed to by on an other page.

You haven’t answered my question if the generated URL is correct. But it seems like rewrites are not working in your system. Is the .htaccess file in the folder, can’t see it in your screenshot, but hidden files are not shown in your system, it seems.

Please enable hidden files and check if you have copied the file.

You can toggle showing/hiding files with a dot using CMD+Shift+.

oh no. You are right. The URL is incorrect. –> But how could that happen?

.htaccess hidden but there.

What is the generated URL?

You can put


anywhere, for example in your footer snippet.

BTW: You have two pages with the same URL in your structure, 0_opener and 1_opener, that’s not possible.

oh thanks.

there you can see the url^^

Well, you said the URL is not correct, so what is the expected URL? With a subfolder?

What is your environment? Are you using the built-in server, maybe?

Well i was thinking it is worng, cause when i copy it in the bowser it is bringing me to the error page.
I am not shure how i expacting the URL to look like, to be honest. – so maybe it is right…

I’am using mamp(Version 4.2.1 (852)).

But i guess the problem of how to get an URL is solved. right? maybe we should make a new subject…

Yes, it definitely is.

However, what is the URL that is shown in the browser for the home page?

It shows: http://localhost:8888/error when i click the link…