How to get the variables available in a Drupal template

This is such a basic PHP function but easy to forget and hard to find for some reason. Anyway, here are a selection of the best ways to find what variables are available in a template file.

First off, the function you need is:

get_defined_vars();

The quickest way to use it is to put the following in your template file:

print_r(get_defined_vars());

Next, install the devel module. Once installed you will now have a 'Devel' tab available when viewing nodes (if you have the correct permission set up).

With the devel you also get a few handy functions:
Print a nicely formatted array to the message area of the page:

dpm(get_defined_vars());

Dump the variables to a temporary log file: /tmp/drupal_debug.txt

dd(get_defined_vars());

To watch the file in your terminal:
tail -f /tmp/drupal_debug.txt

or
tailf /tmp/drupal_debug.txt

Post new comment

By submitting this form, you accept the Mollom privacy policy.

User login

Author of...

  • @drupalninja yes I think that's what I did. Actually, I think that's still a table view and I overrode the table template. 15 years 13 weeks ago
  • @drupalninja I did it here on views 2: http://2tu.us/1l77 15 years 13 weeks ago
  • @drupalninja I think you can have a look at the links the table view produces and then just add the same links yourself 15 years 13 weeks ago
  • huh, is it only Konqueror that tells you if a link will open in a new window? 15 years 14 weeks ago
  • Mac dvi adapter needed. #Mac #Fosdem #fail 15 years 14 weeks ago
  • RT @Casablanca: RT @philhawksworth Hoping to find a #Drupal Legend at #fosdem to join us working at @TheTeam in London 15 years 14 weeks ago
  • Doing my put to put a nail in the coffin for IE6 http://2tu.us/1ja7 15 years 14 weeks ago
  • @leisa, is your javascript turned off? 15 years 15 weeks ago
Oliver Polden