Home ›
Example of hook_block in Drupal 6Example of hook_block in Drupal 6
Searched words:
multiple blocks Drupal pages
define block in code
<?php
/**
* Implementation of hook_block().
*/
function fightfi_block($op = 'list', $delta = 0) {
$block = array();
switch ($op) {
case 'list':
$block[0]['info'] = t('Sidebar Links');
$block[1]['info'] = t('Footer Links');
return $block;
case 'view':
switch ($delta) {
case 0:
$block['subject'] = t('Sidebar Links');
$block['content'] = "super weak";
break;
case 1:
$block['subject'] = t('Footer Links');
$block['content'] = "super weak";
break;
}
return $block;
}
} // end function fightfi_block
?>The interaction of configuration and code can get pretty confusing, so to be perfectly clear, this code makes two blocks available, they show up on the admin/build/block page, and then you can enable (and place) each block individually. Your site configuration and theme, that is, call hook block with different values of delta.
Comments
Add a block on the top roght corner of my site
I was wondering how to add a block to the top right corner of my site using hook_block. I would like to have my log in panel in that location.
Thank you in advance for your answer.
You add new block locations in the theme
Hi eloralon,
Hook_block is for defining new blocks themselves, if you have a block you like already (such as user login) and want to put it somewhere else, that you cannot reach with the admin/build/block page, you create a new region in your theme.
This is pretty simple; in Drupal 6 you just add an entry to your theme's .info file and print a corresponding variable in your page.tpl.php file.
In agaric_example_theme.info:
regions[topright] = ToprightAnd in page.tpl.php:
<?phpprint $topright
?>
(Surround the above with whatever divs or HTML markup you need to position it well with CSS.)
Clear the theme cache (saving the theme page should do it if devel is not installed) and you'll be able to assign blocks to this new region!
See more at http://drupal.org/node/171224
Post new comment