Skip to content

Instantly share code, notes, and snippets.

@LarsEliasNielsen
Created March 6, 2014 09:07
Show Gist options
  • Save LarsEliasNielsen/9385801 to your computer and use it in GitHub Desktop.
Save LarsEliasNielsen/9385801 to your computer and use it in GitHub Desktop.
Drupal 7 Module Development: Content callback in block
<?php
/**
* Implements hook_block_view().
*
* Creates content for our block. It sets the title for the block, and returns
* our news (from our custom callback) as a ul-list, with the id 'espn-news'.
*
* @url: https://api.drupal.org/api/drupal/modules!block!block.api.php/function/hook_block_view/7
*/
function espn_news_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'espn_news':
// List attributes.
$attributes = array(
'id' => 'espn_news',
);
// Set block title.
$block['subject'] = t('ESPN News');
// Get content from API.
$items = espn_news_api_content();
// Print list.
$block['content'] = theme('item_list', array(
'items' => $items,
'type' => 'ul',
'attributes' => array(
'id' => 'espn-news',
),
));
}
return $block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment