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 nicknewbie on
Confused!
This is what I have :
if($is_front){
return false;
}else{
return true;
}
Not so complicated. (Yes I know that I could just exclude the front page but there are other conditionals to add once this works)
$is_front shows as true on the home page and false on every other page (who'd of thunk it?) but the block shows on all pages. And I am not sure why....
thanks
Nick
Comments
You can use instead of php
You can use
<front>
instead of php code , and select 'Show on every page except the listed pages.' in Page specific visibility settings. No need to use PHP code.$is_front is set only when
$is_front is set only when you are on the front page of the site. The $is_front variable is not set for "listing" pages.
Use
if($page==0) instead of if($is_front).
$is_front is set strictly for the front page
use
<front>
instead of php code is always better option for page specific visibility settings..
The $is_front variable is only defined in page templates in the theme. It is undefined in your blocks.
In blocks you can use drupal_is_front_page()
Thanks
@nirmal - yes, that is what I meant. If I use
<front>
I cannot add other php conditionals in.@ abhijeetsandil - well, $is_front is true on the front page and false on the other pages. I var_dumped it to check this. My understanding was that $page==0 would specify all the front-page-like pages. I read this but am not 100% on what it actually means...
@cog.rusty - ah a light-bulb moment ! Yes, of course. Thank you.
.
By the way, $page in a node template is TRUE when you are in a full node page and not in a teaser list page.
See:
http://api.drupal.org/api/drupal/modules--node--node.tpl.php/6
http://api.drupal.org/api/drupal/modules--system--page.tpl.php/6