block_example_block

Definition

block_example_block($op = 'list', $delta = 0)
developer/examples/block_example.module, line 31

Description

Implementation of hook_block().

This hook both declares to Drupal what blocks are provided by the module, and generates the contents of the blocks themselves.

Code

<?php
function block_example_block($op = 'list', $delta = 0) {
  // The $op parameter determines what piece of information is being requested.
  if ($op == 'list') {
    // If $op is "list", we just need to return a list of block descriptions. This
    // is used to provide a list of possible blocks to the administrator.
    $blocks[0]['info'] = t('A simple text string');
    $blocks[1]['info'] = t('An empty block');
    return $blocks;
  }
  else if ($op == 'view') {
    // If $op is "view", then we need to generate the block for display purposes.
    // The $delta parameter tells us which block is being requested.
    switch ($delta) {
      case 0:
        // The subject is displayed at the top of the block. Note that it should
        // be passed through t() for translation.
        $block['subject'] = t('Title of block #1');
        // The content of the block is typically generated by calling a custom
        // function.
        $block['content'] = block_example_contents(1);
        break;
      case 1:
        $block['subject'] = t('Title of block #2');
        $block['content'] = block_example_contents(2);
        break;
    }
    return $block;
  }
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.