4

How can I see what variables are available to me on the page i am viewing via the PHP Execute block? I'm trying to do a dsm($node) but that doesnt seem to work. Neither does dsm($page).

2 Answers 2

2

Drupal doesn't define a global $node or $page object, those are created within the context of various functions during the page build.

To get the node object on a full node page, you can use menu_get_object():

$node = menu_get_object();

For the page array, you'll need to implement hook_page_alter():

function MYMODULE_page_alter(&$page) {
  dpm($page);
}

As a general rule PHP's own get_defined_vars() function will get you all the variables available in the current context. But it won't be useful to find those two particular vars as they won't be available in the context of a devel PHP form execution.

3
  • 2
    thanks.... what i dont understand is why is it called menu_get_object when your fetching the node object? Jun 6, 2013 at 22:20
  • It is a bit confusing - it's returning the object (node, taxonomy term, user) that's attached to the current menu path. The function just defaults to use a node, if you were on a taxonomy term page you could use menu_get_object('taxonomy_term', 2) to get the $term object, etc.
    – Clive
    Jun 6, 2013 at 22:22
  • confusing indeed... Jun 6, 2013 at 22:35
3

Drupal loads all variables into $variables.

So in the PHP block just load: <?php dsm($variables); ?>.

For dsm to work you need the Devel module installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.