Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Stijn Geens on
Is there a function similar to <?php if ($is_front): ?>
, to check if the current page is the contact page (for example) ?
Comments
You could use $title to
You could use $title to compare to the title of your contact page (it can be different depending on the site).
Hi paean99,
Hi paean99,
I tried to use
<?php if ($title != ‘Contacteer ons’): ?>
, but then I get the error "syntax error, unexpected T_STRING".<?php if ($title !=
<?php if ($title != ‘Contacteer ons’): ?>
has the wrong apostrophes and it should be !== not !=You should also be certain that 'Contacteer ons' is the correct title. You should already have a
<?php print $title; ?>
in your page.tpl.php to help you discover it.This solution can be accompanied with an
<?php if ($title): ?>
. An isset tactic might be necessary here since the title is not an absolute in every pages. Although in the case of the drupal contact form it isn't normally a concern.The current_path() is a better and more general solution.
if(current_path() == 'contact')
is correct if your path for the contact form is mysite.com/contact. It could be different in your case...Any of these solutions can be broken if you later change the title or the url.
Thank you, this is very
Thank you, this is very helpful. I used the current_path() function and it works like a charm.
There isn't a function, but
There isn't a function, but you can use:
if(current_path() == 'contact')
Hi Jaypan,
Hi Jaypan,
When I use your code I get the error "Use of undefined constant ‘contact’ - assumed '‘contact’' in include()".
I'm using this code in page.tpl.php from the Venture theme.
What am I doing wrong?
What am I doing wrong?
You're not showing us your code.
I'm sorry. Here is the code
I'm sorry. Here is the code that i've used:
Wrong apostrophes in this
Wrong apostrophes in this case also. The character code is different.
Use this instead
It seems the same but it has the correct apostrophes. The colours should give you a hint.
It works like a charm now.
It works like a charm now. Thanks!