Right way to call theme functions

Posted on Friday, June 12, 2015
Right way to call theme functions


Drupal core and contrib modules defines theme functions. These theme functions can be defined by themes as well.

hook_theme() implementations is where all the information exists. Theme functions are writen as hook_foo() or hook_fooxyz(), but we should never call a theme function directly. By calling it directly we will loose the benefits of Drupal theming layer such as overriding, suggestions, etc.

Example on how to call theme_image() the right way:

Right way

print theme('image', array('path' => 'image/path/image.png''alt' => 'New image'));

Wrong way

print theme_image(array('path' => 'image/path/image.png''alt' => 'New image'));


Further information and documentation can be found at https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme/7.



Helen Mart (not verified)

Saturday, May 6, 2017

According to my knowledge about any article can become helpful for the reader when there is some informative information is included in it. I am very pleased to check this wonderful post. This coding will be more useful for me in the future while working because I am a developer and keep making numerous site as last month made a e commerce website development where. Therefore like staying on those places where these types of relevant information is available. I desire to add this platform into my sheet because here tremendous data are available for users.

hellen jos (not verified)

Thursday, June 8, 2017

I have studied the Drupal functions but I don't know the right way of implementing the code. Here you have provided the right way to call the theme function and is very helpful for me. Keep sharing the more informative article like this.manufactured homes for sale

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.