<
Neerav Mehta
Founder & CEO
We use Drupal hooks to create a block from custom module. In Drupal 6, hook_block() was used. This function has been redefined in Drupal 7 as the following 8 functions:
Here we will develop a basic block (assuming that you already know how to create a custom module in Drupal 7) and hence will use only "hook_block_info()" and "hook_block_view()".
/**
* Implements hook_block_info().
*/
function mymodule_block_info() {
$blocks['mymodule-blockname'] = array(
'info' => t('Administrative block title'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function mymodule_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'mymodule-blockname':
$block['subject'] = t('Block Title');
$block['content'] = t('Hello World!');
break;
}
return $block;
}
<none>
All pages except those listed/Only the listed pages
In both cases, you can specify the pages by their paths (as shown above). The * is a wildcard character. For eg: as per the above setting, the block will be visible for the path http://www.sitename.com/content and http://www.sitename.com/content/xyz. For frontpage, <front>
can be used.
Pages on which this PHP code returns TRUE
Here you can write PHP code between <?php ?>
.
if ($condition) {
// Condition is true. return TRUE to show the block.
return TRUE;
}
else {
// Condition is false. Return FALSE to hide the block.
return FALSE;
}
Note: "Pages Visibility Settings" and "Content Types Visibility Settings" do not work together.
Note: "Pages Visibility Settings" and "Content Types Visibility Settings" do not work together.
Neerav Mehta
Neerav Mehta is the Founder & CEO of Red Crackle. With sterling qualities, Neerav’s technological acumen is firing a generation of progressive companies on the digital path. With an undergraduate degree in Electrical Engineering from India's most prestigious institution IIT Bombay and having spent seven years developing and contributing to the launch of AMD's innovative line of computer products, Neerav founded Red Crackle where he is lauded for his dynamic and innovative genius.
Let’s get you started!