The Definitive Guide to Drupal 7

Finding the Contents of $variables

The contents of the $variables array are different for each theme hook; even the contents of the same theme hook vary based on other factors, such as the view mode or user role.

The first thing to do after creating the function is to print the array and find out what’s inside for you to work with. As explained in the “Finding Available Variables in the Theme Layer” section, using the dpm() function is a great way to do this, as shown in Listing 16–7.

Listing 16–7. Printing variables to the screen for debugging purposes
  1. <?php
  2. /**
  3.  * Implements template_preprocess_node().
  4.  */
  5. function dgd7_preprocess_node(&$variables) {
  6. dpm($variables);
  7. }

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.