Hi,
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 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:
http://kombas.de/
http://kombas.de/newsletter/
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…
With
$site->uri->path(1)
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
http://kombas.de/newsletter
but not
http://kombas.de/newsletter/completed
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 }?>
http://getkirby.com/docs/cheatsheet/request/path
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
myurl.de/part1/part2/part3/
If I need to check part2 I used in Kirby 1.0
$site->uri->path(2)
have a look at the link, there’s nth() as well …
Or go for http://getkirby.com/docs/cheatsheet/page/diruri 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
}