Sunday, May 13, 2012

Example of hook_block in Drupal 6



/**
* Implementation of hook_block().
*/
function modulename_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.

No comments: