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

  • The A-Team, a bit annoying but enjoyable. Why did they not play the classic soundtrack?! 14 years 40 weeks ago
  • Google maps track of my solo flight http://is.gd/dHTlr 14 years 41 weeks ago
  • First solo flight, ride to work voucher arrived. My shiny new bike awaits. It's been a good day. Night out to finish it off I think. 14 years 41 weeks ago
  • Successfully just did my first glider solo! 14 years 41 weeks ago
  • @leisa not the one here?! How quick is google! http://bit.ly/9e742A 14 years 41 weeks ago
  • A quick blog about typography and ligatures: http://oliverpolden.com/balancing-seo-and-design-ligatures 14 years 44 weeks ago
  • Going back to #kubuntu from #ubuntu. File already exists: Cancel, Skip, Replace, where is rename?! http://bit.ly/aYWWYk 14 years 45 weeks ago
  • less than a month to go until Microsoft stop supporting IE6 Wohoo! http://support.microsoft.com/gp/lifesupsps/#Internet_Explorer 14 years 46 weeks ago
Oliver Polden