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?
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; ?>
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; ?>
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
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.
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
I’d also recommend checking for the (intended) template.