Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a block that I need displayed only on the main page of a node.

I can get it to display on node/1/view by putting node/*/view in the conditions, but that only works if view is in the URL. I want it to show whether I go to node/1/view or node/1, but NOTHING else. If I try node/* it shows it for every node page, not just node/1. I also tried node/*/ but that didn't work at all as it appears the ending slash is being removed.

share|improve this question

migrated from stackoverflow.com Dec 20 '11 at 15:05

2 Answers

up vote 2 down vote accepted

In the visibility textarea of your block, select PHP code and put the following:

<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == '' || arg(2) == 'view')) {
  return TRUE;
} else {
  return FALSE;
}
?>
share|improve this answer
Exactly what I was looking for, this even works with taxonomy! Perfect! Thanks so much. – Piontek Media Dec 20 '11 at 18:48

If you really want you can simply add node/1 and node/1/view to the visibility list. However this is not the Drupal way imho - Drupal expects that default local tasks aren't explicitly specified in the URL (and this is why for example it outputs node URLs as node/1 and not node/1/view in the first place). Path based rules like this can make a system more brittle - and doing it in a way that doesn't fit in with existing Drupal behaviour is asking for trouble imho. What is it you're trying to do?

share|improve this answer
I need it to be automatic as users will be signing up and getting a node page to customize. There will be thousands of them, and more added every day. Each node will act as a users own personal page and needs to have a block shown only on the main page of it (both node/1/view and node/1, but there will be thousands of nodes with this same setup). Hope that clears it up. – Piontek Media Dec 20 '11 at 15:25
@Piontek Media So the problem is how to have the block display on some nodes and not others? – Andy Dec 20 '11 at 16:15
Not quite, the problem is how to have the block display on all nodes front page, and only the front page. – Piontek Media Dec 20 '11 at 16:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.