Debug Drupal variables in JavaScript console
language: Drupal 6.x
JavaScript dev tools in Chrome and Firefox are pretty handy when debugging complex objects with console.log()
But what if you want to put PHP in there for examination?
You can print_r onto the page in a nice drupal message with drupal_set_message(), but that might not cut it for complex variables, it gets tough to see who's who's parent...
To put it in your favorite JS debugger, with hierarchy clearly displayed try this:
<?php function yourmodule_footer(){ drupal_add_js('console.log('.json_encode($mystery_variable).')', 'inline', 'footer'); return ''; } ?>
