19

If I'm used to PHP's var_dump() and print_r() to check the value of a variable, how can I evolve to inspect things in Craft where Twig's dump isn't available?

  • 4
    In what cases would Twig's dump() function not be available? You mean just when Dev Mode isn't enabled? – Brandon Kelly Jun 12 '14 at 1:33
  • 2
    Yes, that is apparently what I mean. I've learned something, but now I feel a bit daft. – Matt Stein Jun 12 '14 at 1:37
13

There's the dbug plugin which should give you what you are after, template side.

This plugin adds a helpful dbug method to your Craft templates. This will help you see in the dark - figure out what kind of variables you are dealing with, and what methods they implement.

  • Perfect, thank you! – Matt Stein Jun 12 '14 at 1:29
  • The dbug plugin isn't supported anymore, and Luke (the author) recommended craft_kint instead. – Matt Stein Aug 31 '16 at 17:50
20

If you have devMode set to "true" in your config files, you can use "dump" in a twig template like this without any plug in needed:

{{ dump(myArray) }}
  • 5
    Tip: devMode is enabled by adding 'devMode' => true to craft/config/general.php. – Simon East Jul 30 '16 at 10:56
7

There's a plugin called "craft inspector" https://github.com/adrianmacneil/craft-inspector that has come in handy.

{{ craft.request | inspect }}
{{ inspect(craft.request) }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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