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.



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.