How do I state "If current page is not X"?

I have a bit of code in my footer that I only want to display if the current page is NOT the contact page.

How do I do that?

You could check for the $page->id()

<?php if ($page->id() != 'contact'): ?>
  // do stuff
<?php endif; ?>

… or you could add a checkbox field to the blueprint to let the editor choose, if the content should be displayed. Assuming the fields’ key is myfield

<?php if ($page->myfield()->bool()): ?>
  // do stuff
<?php endif; ?>
1 Like

Or you can use a contact.txt template for the contact page and check if the current page doesn’t use that template

<?php if ($page->intendedTemplate() != 'contact') : ?>
    # Your Code
<?php endif; ?>
2 Likes

what about using is()

if($page->is(page('contact')) == false) {...}
3 Likes

This will also work. I’m personally a fan of the intendedTemplate() solution because this way you’re free to change the url and/or title of the page without breaking the site :slight_smile:

1 Like

unless you disallow the user in the panel to change templates your solution is not save either.

edited: well saver, but not save. one might say. :wink:

That is indeed true but since in the panel the template/blueprint is tied to the fields is quite unlikely that a user wants to change that. Also the change of title/url is something you might want/need to do even if you code a site without the panel installed :slight_smile:

I’d also recommend checking for the (intended) template. :slight_smile:

2 Likes