jvc26
jvc26

Reputation: 6503

On Drupal 7, in a custom block, how can I find out the current page?

On Drupal 6, I used to have a custom PHP block which accessed arg(0), to detect which page the user was currently on. To find out whether the user was on the front page, I used:

if (arg(0) == '' || arg(0) == 'home') :

However, this test doesn't appear to work on Drupal 7, as the arg(0) returns node. I was wondering whether there is a better way to check the page - for example the template engine's $is_front which I can access at a block level to check whether the page is the front one.

Thanks for your help,

J

Upvotes: 0

Views: 1432

Answers (1)

Betamos
Betamos

Reputation: 28817

In Drupal 7 there is a function called drupal_is_front_page.

Also as usual you can show/hide the block from the front page simply by providing <front> in the list of paths in your block's configuration page.

Upvotes: 3

Related Questions