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?
Asked
Active
Viewed 1.7k times
20
Matt Stein
- 4,006
- 3
- 26
- 57
-
5In 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 01:33
-
2Yes, that is apparently what I mean. I've learned something, but now I feel a bit daft. – Matt Stein Jun 12 '14 at 01:37
3 Answers
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) }}
John Morton
- 902
- 6
- 9
-
6Tip:
devModeis enabled by adding'devMode' => truetocraft/config/general.php. – Simon East Jul 30 '16 at 10:56
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.
Iain Urquhart
- 388
- 3
- 9
-
The dbug plugin isn't supported anymore, and Luke (the author) recommended craft_kint instead. – Matt Stein Aug 31 '16 at 17:50
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) }}
jnowland
- 846
- 6
- 16