hook_block_view

Versions
7
hook_block_view($delta = '')

Return a rendered or renderable view of a block.

For a detailed usage example, see block_example.module.

See also

hook_block_info()

@see hook_block_view_alter()

See also

hook_block_view_MODULE_DELTA_alter()

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 required elements 'subject' (the block's localized title) and 'content' (the block's body). The 'content' element may be a renderable array (preferable) or rendered HTML content.

Related topics

Code

drupal-7/modules/block/block.api.php, line 199

<?php
function hook_block_view($delta = '') {
  // This example comes from node.module. Note that you can also return a
  // renderable array rather than rendered HTML for 'content'.
  $block = array();

  switch ($delta) {
    case 'syndicate':
      $block['subject'] = t('Syndicate');
      $block['content'] = theme('feed_icon', array('url' => 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'] = theme('node_recent_block', array(
            'nodes' => $nodes,
          ));
        } else {
          $block['content'] = t('No content available.');
        }
      }
      break;
  }
  return $block;
}
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options