How can I pass a renderable array from within a block?

$block['content'] = array(
  '#theme' => 'image_formatter',
  '#variables' => array('path' => 'hello.png'),

How do I pass the variables that image_formatter needs when I use a renderable array from within a block?

2 Answers 2

$image = array(
  '#theme' => 'image_formatter',
  '#image_style' => 'thumbnail',
  '#item' => array(
    'uri' => $user->picture->uri,
    'alt' => '',
    'title' => '',
$block['image'] = $image;

It is a bit confusing until you've done it a couple of times (it had me scratching my head for ages); you need to prefix the names of the variables with a #, as properties of the array:

$block['content'] = array(
  '#theme' => 'image_formatter',
  '#path' => 'hello.png',
  '#alt' => 'Hello!'

That would be the equivalent of:

theme('image_formatter', array('path' => 'hello.png', 'alt' => 'Hello!'));
  • The above throws this error at me Recoverable fatal error: Argument 3 passed to l() must be an array, string given, called in .../modules/image/image.field.inc on line 633 and defined in l() (line 2340 of ../includes/common.inc). May 10, 2012 at 18:21
  • How strange, I was just about to comment on this...my answer has the wrong variable names for theme_image_formatter(), @milkovsky's answer is spot on
    – Clive
    May 10, 2012 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.