Friday, September 16, 2011

Drupal Coding Lifeline

dpm(get_defined_vars());

That little bit of PHP is an absolute lifeline for module and theme coding in Drupal. If you need to know what variables are available in a given context, that's what to use. Works in .tpl.php files and in .module or .inc files, especially where hook_theme may be in use. print_r and var_dump are of course reliable standbys, but time and time again, dpm() has rescued me from hours of very painful head banging against desk.


Far better explanations and listings of Drupal debugging tools and their usage are both here

- http://www.thingy-ma-jig.co.uk/blog/02-10-2007/hugely-useful-hugely-undocumented

and here

- http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-development-tips-list-all-available-variables-and-backtrace-a-page/