If page is front page

I can use this:

<?php echo $page->uri() ?>

When I’m at home I get home but I expected it to be nothing because it’s the root. How can I check if the url is the start page? Something like:

if( $page->isHomePage() ) { echo 'Home'; }

Or if I could get it like this:

echo site()->page()->homePage();

to get which page is home. Could not find it in the docs.

http://getkirby.com/docs/cheatsheet/page/is-home-page

And to get the home page, you can always just use page('home').

1 Like

Ahh, how could I miss that one. How embarrassing, I was writing it correctly in my example above then.

… in a “normal” Kirby installation.

But if you install e.g. like http://www.getkirby-themes.com/themes/baseblog/ with c::set('home', 'blog') in your config.php, then that code shows an empty string.

Therefore you can use $site->homePage(), which returns the $page object for the home page, instead.

Good luck!

2 Likes

Good call!!! :smile: (only adding so many ! because I need to have 20 characters in this post)

Did you look at $page->isHomePage()?

This may be helpful in PHP code like r( ... ) or ecco( ... ).

You can use the url of a page (e.g. $site->homePage()->url() ), not tested yet.

Yes, I now use isHomePage.

I will look if ecco or r will make sense in my project. I knew about them, but sometimes I forget that they exist. Good reminder, thanks!