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?
-
5In what cases would Twig's dump() function not be available? You mean just when Dev Mode isn't enabled?– Brandon KellyCommented Jun 12, 2014 at 1:33
-
2Yes, that is apparently what I mean. I've learned something, but now I feel a bit daft.– Matt SteinCommented Jun 12, 2014 at 1:37
3 Answers
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.
-
The dbug plugin isn't supported anymore, and Luke (the author) recommended craft_kint instead. Commented Aug 31, 2016 at 17:50
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) }}
-
6Tip:
devMode
is enabled by adding'devMode' => true
tocraft/config/general.php
. Commented Jul 30, 2016 at 10:56
There's a plugin called "craft inspector" https://github.com/adrianmacneil/craft-inspector that has come in handy.
{{ craft.request | inspect }}
{{ inspect(craft.request) }}