hook_block_view

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 hook_block_view($delta = '')

Return a rendered or renderable view of a block.

Parameters

$delta Which block to render. This is a unique identifier for the block within the module, defined in hook_block_info().

Return value

An array containing the following elements:

  • subject: The default localized title of the block. If the block does not have a default title, this should be set to NULL.
  • content: The content of the block's body. This may be a renderable array (preferable) or a string containing rendered HTML content.

For a detailed usage example, see block_example.module.

See also

hook_block_info()

hook_block_view_alter()

hook_block_view_MODULE_DELTA_alter()

Related topics

Code

modules/block/block.api.php, line 207

<?php
function hook_block_view($delta = '') {
  // This example is adapted from node.module.
  $block = array();

  switch ($delta) {
    case 'syndicate':
      $block['subject'] = t('Syndicate');
      $block['content'] = array(
        '#theme' => 'feed_icon', 
        '#url' => 'rss.xml', 
        '#title' => t('Syndicate'),
      );
      break;

    case 'recent':
      if (user_access('access content')) {
        $block['subject'] = t('Recent content');
        if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) {
          $block['content'] = array(
            '#theme' => 'node_recent_block', 
            '#nodes' => $nodes,
          );
        }
        else {
          $block['content'] = t('No content available.');
        }
      }
      break;
  }
  return $block;
}
?>