Drupal | Programming | Tips
2 invaluable Drupal development tips: list all available variables and backtrace a page
The Drupal Devel module includes some invaluable functions that make working with Drupal much much easier. A short list of these functions can be found at this post. One of these is the dpm() command (which I would guess stands for “Drupal Print Message,” or at least that’s how I remember it). Given an array or object, this function will output a div structure at the top of your page that you can use to visually walk through the contents of either of these sets of data. Combine this with existing PHP debugging and instrospection commands and you have a very useful and powerful development tool at your disposal. For example, place this at the top of your Drupal theme’s page.tpl.php template:
<?php dpm( get_defined_vars() ); ?> |
Now when you navigate to your page you will have a clickable bar at the top that will list all variables available to the page when it loads, which you can access via the code in your theme page template if you want.

Or maybe you would like to know what path your page took through Drupal’s architecture to its final incarnation, use dpm() with PHP’s debug_backtrace() function. This will output an array of each function your page contents went through before they were output to the browser, plus it shows the location of these functions. Try this in place of the code snippet above:
<?php dpm( debug_backtrace() ); ?> |


July 8th, 2009 at 7:41 am
hey….just a friendly tip. next time, put in 5 minutes of research before writing articles like this. the function you have called, dpm(), is not built-in to drupal, it comes with a module called devel. and if you have that module installed, you don’t really have to do all this manually, you can just check out the dev_load and dev_render tabs on each page….
i put in the code without having drupal installed, and was wondering why the function was termed as undefined…
July 9th, 2009 at 2:50 am
Hi Neil Satra,
Thank you for pointing out the Dev Load and Dev Render tabs for those that may not have been aware that they existed. However, I would give you the same advice. If you took 5 minutes to read my article you would have discovered that I say dpm() is part of the Devel module in the first paragraph. Also, using the Devel tabs as you suggested only gives access to the properties of the $node object, whereas dpm( get_defined_vars() ); returns all variables available to a particular Drupal page. Additionally, Dev Load and Dev Render do not provide page backtrace information.
Perhaps you could contribute to the community knowledge base and write a post on Dev Load and Dev Render and post a link to it in the comments here?
August 22nd, 2009 at 1:57 pm
I found this article informative and handy. Thanks.
September 10th, 2009 at 4:53 pm
I too found this “informative and handy”. I’m new to drupal and web development and little tips like this help a lot. Thanks.
November 17th, 2009 at 10:41 am
great article one question though is there anyway you can call the arrays that are generated from the dev renderer tab
November 17th, 2009 at 10:09 pm
Hi Pablo,
I’d have to look into it… but for the sake of giving you a quick reply, if you click on the devel tab I would think the arrays would become available as variables for the page, in which case you could view them using
dpm( get_defined_vars() );as above.January 16th, 2010 at 8:10 pm
Excellent article – very useful!!
Thanks,
Jared
February 24th, 2010 at 11:09 am
Very useful article. Thanks.
April 20th, 2011 at 10:41 am
[...] See also: http://www.lullabot.com/articles/quick-and-dirty-debugging http://drupal.org/project/visualize_backtrace http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-developmen… [...]
August 8th, 2011 at 1:42 pm
RE: using dev tabs vs coding
I wanted to see the variables in a view, but the dev tabs don’t appear in a view, so I coded them into the views-view-grid.tpl template, then the views-view-fields.tpl template, and was then able to see the variables I needed to add some graphics to the view output. Tabs are nice, but sometimes you have to code the dpm().
September 23rd, 2011 at 1:29 am
I had to put a print before the dpm function, incase someone else needs it
-m
August 29th, 2012 at 2:58 pm
Hiya, thanks for the tip. A quick update, it looks like the backtrace func is now **ddebug_backtrace()** and it prints out by default, not needing the dpm() wrapper. Not sure when it changed.