Restricting blocks to certain pages

Last modified: November 19, 2007 - 14:53

Below the Page Specific Visibility Options options, you will see a large text box. On each line, you can specify which pages that block will appear on -- or not appear on, depending on what you selected above.

The following are some annotated examples. They all assume that you choose the second option above; if you chose the first option, blocks will appear on all pages other than what you specify below. You're welcome to add more than one listing, each separated by lines. (Note that you cannot specify pages on which blocks appear as well as pages on which blocks do not appear. It is either one or the other.)

<front> Specifies that the block appears on the front page.
node/42 Specifies that the block will appear on the item with the node
ID of 42.
aggregator Specifies that the block appears on just the aggregator.
blog/* Specifies that all URLs that start with blog/ will show the
block. Note: if you want the block(s) to also appear on the main
blog page, you need to add blog (that is, without the
trailing slash) as well.

Some users have reported they receive the error "warning: Delimiter must not be alphanumeric or backslash in [your drupal install] modules/block.module on line 354." if they do not surround their paths in <> like <node/42>

Another example, if you have HTML, Javascript or PHP blocks you don't think are necessary for administrators to see, you can select "Show on every page except the listed pages." and use the following
wildcard for the block:

  • admin/*

Administrators can select which content type blocks appear on as well. This can be found under "Content specific visibility settings" after clicking the "configure" link for an individual block. Choose which content type blocks appear on by checking the box next to that content type. You can use content type-specific blocks in conjunction with the above restrictions based on URLs.

Examples of using PHP for visibility combined can be found in the PHP Snippets section of the Handbook in the article Overview Approach to Block Visibility

 
 

Drupal is a registered trademark of Dries Buytaert.