The Definitive Guide to Drupal 7

Calling Theme Functions

Throughout this chapter we refer to theme functions as theme_this() and theme_that(). That’s what the functions are named and usually referred to as. However, you should never call a theme function directly. Doing so will reverse the wonderful functionality that comes along with Drupal’s theme layer, such as overrides, suggestions, etc. Always use the theme() function to generate theme output. It takes care of routing the request to the appropriate theme function. For more information on how this works, see http://api.drupal.org/api/function/theme/7.

Using theme_image(), Listings 15–13 and 15–14 illustrate the right and wrong way to call theme functions, respectively.

Listing 15–13. The Correct Way to Call a Theme Function.
  1. <?php print theme('image', array('path' => 'path/to/image.png', 'alt' => 'Image description')); ?>
Listing 15–14. The Wrong Way to Call a Theme Function
  1. <?php print theme_image(array('path' => 'path/to/image.png', 'alt' => 'Image description')); ?>

You are reading content from two chapters on Theme Development from The Definitive Guide to Drupal 7, written by Jacine Luisi and published by Apress on July 19, 2011. All rights reserved.