I have this call to the theme function in my code :

print theme('image_style', 
                'path' => $news_image['uri'],
                'style_name' => 'thumbnail',
                'alt' => $news_image['alt'],
                'title' => $news_image['title'],)

However in the theme function documentation you can read :

Avoid calling this function directly. It is preferable to replace direct calls to the theme() function with calls to drupal_render() by passing a render array with a #theme key to drupal_render(), which in turn calls theme().

So, how do I rewrite the above simple function using drupal_render ?

1 Answer 1


Something like this...

$build = array(
  '#theme' => 'image_style',
  '#path' => $news_image['uri'],
  '#style_name' => 'thumbnail',
  '#alt' => $news_image['alt'],
  '#title' => $news_image['title'],

$rendered = drupal_render($build);

Where every named variable you would normally pass to the theme() function as the second parameter becomes a #-prefixed key in the render array.

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.