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

  • @darthsteven or disabled javascript? 15 years 33 weeks ago
  • Having a look at Drupal 7 makes me wanna ditch my efforts to evaluate modx for 'smaller' sites. Is it familiarity or is Drupal just better? 15 years 37 weeks ago
  • @bridgecourt Modx 1.0 15 years 38 weeks ago
  • Giving Modx a go. First impressions: install 'ok', responsive javascript admin interface. with nice tree nav of site. Nod test = good. 15 years 38 weeks ago
  • Front End Drupal mentions the Textimage module. Will be giving that a try soon: http://2tu.us/m6n 15 years 40 weeks ago
  • Why haven't I found this before?!! Firebug for ie. My life just got a lot easier. http://2tu.us/li0 15 years 41 weeks ago
  • Drupal's looking good: http://bit.ly/rKrpS 15 years 41 weeks ago
  • Taking a look at kompozer. OS alternative to Dreamweaver for win, lin & mac :-) http://www.kompozer.net 15 years 43 weeks ago
Oliver Polden