Created
March 6, 2014 09:07
-
-
Save LarsEliasNielsen/9385801 to your computer and use it in GitHub Desktop.
Drupal 7 Module Development: Content callback in block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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