4

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

print theme('image_style', array( '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

7

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.