Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Introduction
This is a very simple snippet I use to display all the Drupal variables available to a page when I'm testing/debugging a site.
Step 1 of 1
Using a text editor like Pspad or notepad, open up your node.tpl.php file and paste in the following snippet at the bottom of the file.
<?php
print '<pre>';
var_dump(get_defined_vars());
print '</pre>';
?>
An alternative: using dpm()
If you have installed and enabled devel module, you can view the variables by adding this code to your .tpl.php file:
<?php dpm(get_defined_vars()); ?>
You will then see a yellow clickable output, which allows you to see which variables are available.
Attachment | Size |
---|---|
dpm-variables.png | 51.47 KB |
Comments
Thanks
Thanks
Any updated instructions for
Any updated instructions for this in Drupal 8 or 9?
I'd like to see what variables I have available when using my mytheme.theme file. Calling dpm() doesn't seem to do anything
Or even I might like to just take a look into the $variables that I have available within a hook in that theme file.
print_r() not only runs out of memory, but it's also a bit clunky... I wanna see what's inside the black box tho ! lol
Use devel module and then Try
Use devel module and then Try with dpm() or dvr() functions to reduce the memory.
www.thirstysix.com
The easiest way may be to
The easiest way may be to install Devel module and use it like this?
where would you put this?
where would you put this?
Especially when your theme has only twig files?
Use dpm()
Like @ThirstySix recommends,
dpm()
is probably better. Add it to theTHEMENAME.theme
file, right after thefunction hook_preprocess_html()
declaration. For example in the Olivero theme, add it around line 21 in/core/themes/olivero/olivero.theme
, like this:Use
dvr($variables);
to get only the variables.See https://www.drupal.org/docs/contributed-modules/devel/dpm-and-other-deve... for more.