I enabled Twig debug and I tried to debug some custom fields. However, if I try this with debug() or kint(), my application always crashes. My PHP memory size is currently 512MB; I assume that should be enough.

I realise that node is a bit too much to debug, so I tried debugging a field as in node.field_video, but that didn't work out as well.

How do I check the content of variables passed to a template file?


You can follow document.

To dump only the available variable keys use:

{{ dump(_context|keys) }}

In this case you can use:

{{ kint(node|keys) }}

Or you can follow topic

Create a /modules/contrib/devel/kint/kint/config.php file and add / modify the line $_kintSettings['maxLevels'] = 3; (by @mdrummond on Slack)

The best way: install module twig_tweak and using twig function {{drupal_dump(node)}} to dump variables.
  • 2
    Apparently, you can also do this in your local settings file without having to create a kint config file: $GLOBALS['_kint_settings']['maxLevels'] = 3; – Danny Englander Sep 12 '16 at 17:31
  • @DannyEnglander – Unfortunately $GLOBALS['_kint_settings']['maxLevels'] in settings.local.php is overwritten by the default value in /modules/contrib/devel/kint/kint/config.php nowadays. – leymannx Apr 14 '20 at 15:48

Note that if your fields are inside custom blocks, and you're trying to access those fields, the syntax is slightly different. You'll want to access them this way, with a kint statement inside your custom twig file:

{{ kint(_context) }}

Inside the _context array, I found my fields were then inside the content array. So in my case, I was looking for the value of field_caption - and that was available at

{{ _context.content.field_caption.0 }}

I hope that helps someone else save some time along the way!

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.