Block Page Visibility

Last modified: September 14, 2008 - 00:59

With this module you can set the visibility of your blocks programmatically, using one structured array. Instead determining the block visibility by custom PHP code it provides a pre-defined script, that uses a central configuration function bpv_config().

The visibility is set up in the module code in the config function, example:

<?php
function bpv_config($name) {
 
$blocks = array(
   
'user-0' => array(0, 'user* node*', '', ''),
   
'comment-0' => array(1, '<front>', 'story page', ''),
   
'block-3' => array(0, 'news', '', ''), // custom block with id 3
 
);
  return
$blocks[$name];
}
?>

The key in the array is the ID of the block. The first item in the array determines if the block should be displayed only on the given pages (0), or on the contrary, exactly there not (1). The second item gives you the (space separated) list of pages the visibility depends on. The third item contains the triggering content types, while the last item is just a general purpose boolean, in general you won't need to bother about it.

After adding your block to its home region you have to save its configuration file, so the custom php code can be inserted into the blocks table.

Module page: http://drupal.org/project/bpv

Notes on the Snippets above:

$name is the array key. When the bpv.module calls to check a modules visibility it will use the blocks id (you can get this easily if you check the url of the configure link on a block) as the $name key.

Thus bpv_config($name) will return the row in the array with key $name.

 
 

Drupal is a registered trademark of Dries Buytaert.