Site URI in Kirby 2.0 not working properly


in Kirby 1 i used something like that:

if ($site->uri->path(1) != 'newsletter')

in Kirby 2 this seems to not work anymore, I get a

Fatal error: Cannot access protected property Site::$uri in

Any Tips for my migration because I use this a few times within my website.

What are you trying to achieve?

Maybe one of these is what you are looking for?

What I am controlling with this parsing are page related contents in the sidebare of my 2 col template.

E.g. in this example

if ($site->uri->path(1) != 'newsletter') { FORM CODE }

I show the newsletter subscription box in my sidebar NOT if I am already on the newsletter page.

Look here:

And in Kirby 1.0 this works, but not in 2.0.

In this case, $page->uid() will get what you want.

Unfortunately not really…



I got the first part of the URL after the domain in Kirby 1.0. And this works for subpages of that page too and that’s what I need.

if ($page->uid() != 'newsletter') { CONTENT }

works for

but not

I need query the n-th part of an URL, not a fixed URL itself.

This is a general method on my website because with the old way I was able to show contextsensitive content in my sidebar, depending on key parts of the URL like “/products/" or "/blog/” etc.

I guess I’ve finally found the equivalent to what you used to use:

<?php if (kirby()->request()->path()->first() != "newsletter") { content }?>

But that’s bad. Why such a valuable function became obsolete in 2.0?

Your’s still not what I am looking for, because it does not NEED to be the first part in the URL, could be the n-th part also like

If I need to check part2 I used in Kirby 1.0


have a look at the link, there’s nth() as well …

Or go for and split it to get the top-parent one

$newsletter = $site->find('newsletter');
if(!$page->is($newsletter) and !$page->isDescendantOf($newsletter)) {
  // Show newsletter subscription box