Opposite of $page->isHomePage()

Hi

Is there an opposite to ‘isHomePage’?

Basically I want to say if page is not home page echo …

I have this working but I’m thinking there must be a nicer way. Obviously quiet new to php :smiley:

<?php if ($page->isHomePage()) : ?><?php else : ?> class="bg"<?php endif; ?>

Thanks

you can use the e() helper for this which will echo a string based on a condition.

class="<?php  e($page->isHomePage(), 'home', 'not-home') ?>"

The e() helper is a kirby feature, its not part of PHP.

1 Like

Hello

Yeah I am using the helper elsewhere and I was thinking it could be the key to the problem, so that’s basically saying if page is home page echo home - otherwise not-home. Right?

Yes thats right, If you dont want it to output something for pages that are not the home page, you can set the second bit to null, which i dont think thats that what you want, just showing the ways you can use it.

class="<?php  e($page->isHomePage(), 'home', null) ?>"
2 Likes

Thanks so much for the quick reply and good explanation!