D7 Render Arrays on in hook_block_view

2 replies [Last post]
jghyde
Offline
Last seen: 22 weeks 6 days ago
Joined: 2011-02-07

Drupal 7 wants you to create render arrays to make blocks. Here's the example from

<?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;
}
?>
Source: <a href="http://api.drupal.org/api/drupal/modules--block--block.api.php/function/hook_block_view/7</p>
<p>Does" title="http://api.drupal.org/api/drupal/modules--block--block.api.php/function/hook_block_view/7</p>
<p>Does">http://api.drupal.org/api/drupal/modules--block--block.api.php/function/...</a> anyone know enough about these render arrays to create a block this way?

Joe

jghyde
Offline
Last seen: 22 weeks 6 days ago
Joined: 2011-02-07
Source URL for hook_block_view()
Chris Shattuck
Offline
Last seen: 3 weeks 6 days ago
Joined: 2009-08-16
Hey Joe, I'm guessing you

Hey Joe,

I'm guessing you have, but just in case have you checked out the videos on doing this, starting with http://buildamodule.com/video/drupal-7-core-concepts-how-hooks-work-and-... ? There's three of them that take you through the process in succession.

Let me know if that helps or if you still run into snags.

Cheers!
Chris

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.