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

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

Wrong way

<?php
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.

 

Disqus Comments