20

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?

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

3 Answers 3

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.

1
  • The dbug plugin isn't supported anymore, and Luke (the author) recommended craft_kint instead.
    – Matt Stein
    Commented Aug 31, 2016 at 17:50
22

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) }}
1
  • 6
    Tip: devMode is enabled by adding 'devMode' => true to craft/config/general.php.
    – Simon East
    Commented Jul 30, 2016 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 and acknowledge you have read our privacy policy.

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