Is Devel module's dsm() function available in page.html.twig? If it is not available, is there a way to make it available?

I am able to use dsm() in .theme file but not in page.html.twig.

I am aware of dump() function in .twig. dump() is similar to var_dump() of php and the output is not as clean as Devel module's dsm() function.

Using dsm() or dpr() in page.html.twig causes error and site does not load.

  • I don't personally know the answer to your question, but have a look here: drupal.org/node/1805526
    – Sifro
    Dec 22, 2013 at 23:35
  • @Sifro I am aware of dump() function but it is not very clean.
    – 15dk51
    Dec 23, 2013 at 17:18
  • Yeah I know, but comment #4 says "You can also use kpr, dpr, dsm, etc. if devel module for D8 is downloaded and enabled. psynaptic took care of that" Haven't verified it though
    – Sifro
    Dec 23, 2013 at 19:34

3 Answers 3


Why not just do it in hook_preprocess_page() instead.

function MYMODULE_preprocess_page(&$variables) {
  • As per your suggestion, in the absence of dpm() and dsm() in page.html.twig I used it in my theme's .theme file inside function hook_preprocess_page(&$variables) { dsm($variables);}
    – 15dk51
    Dec 24, 2013 at 5:02
  • The only problem with this approach is if you are debugging a view template or block template. I guess you could use their respective hooks. But I think the better way of doing it is using @Cottser's approach. Aug 7, 2018 at 16:05

The Kint submodule in Devel 8.x now provides Kint debugging functionality in Twig templates.

{{ kint() }}
{{ kint(variable_one, variable_two) }}

Enjoy! Screenshots and a bit more info here: https://drupal.org/node/2218949

And I want to add that I hope the contrib space in 8.x ends up with tons of debugging options, for example I'm looking forward to seeing Ladybug implemented!

  • If you don't mind me asking, how is Ladybug better, why would it be your choice over Kint?
    – Raveren
    Dec 17, 2014 at 7:33
  • Kint is fantastic, and I was happy to spend time working on the Kint/Twig integration for the Devel Drupal 8 module :) I never said Ladybug was better, I just think it's always nice to have more options!
    – star-szr
    Dec 17, 2014 at 11:40
  • Hey, thanks for the kind words and putting up with Kint's terrible means of integration :)
    – Raveren
    Dec 17, 2014 at 17:04

Use twig method for debugging. first go to sites/default/services.yml

and set debug:true

then you can use twig method for debugging.

{{ dump(attributes) }}

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.