13

I want to use dump() in my .twig template (inside custom theme).

The problem is, when I place {{ dump() }} the page is just blank.

I have had:

  1. Set twig.confing debug: true in services.yml.
  2. Cleared cache.

The moment I remove {{ dump() }} everthing works.

After hours of googling I've found some information about mystery $settings['twig_debug'] = TRUE; here (I don't even have such line in my file, but adding it doesn't change a thing) and $twig = new Twig_Environment($loader, array(... (where to find it even?).

I work on clean & fresh Drupal 8 installation, turing debbuing on (step 1.) does include comments in source code (as it should) but use dump() once and all you see is just an blank page.

3
  • Have you checked the drupal log?
    – Eyal
    Commented Jun 19, 2016 at 22:47
  • There is probably a PHP error associated with the blank screen. As far as I know, you want to go with Kint rather than dump() now. See drupaleasy.com/quicktips/…
    – mona lisa
    Commented Jun 20, 2016 at 3:01
  • 2
    Blank screen means mostly memory error, and since dump() prints out all variables it could be a hint Commented Jun 20, 2016 at 6:16

1 Answer 1

13

I agree with the comment left for the question: It seems you have an out of memory issue. Check the error log for the server.

I had the same problem with dump() and kint() in an implementation of template_preprocess_views_view_field(), while trying to output the content of a row, on a clean and fresh Drupal 8 installation. I found a workaround for kint(), which seems to temporary fix the memory issue. Add the following settings in the config.default.php file for the Kint module.

/** @var int max array/object levels to go deep, if zero no limits are applied */
$_kintSettings['maxLevels'] = 4;

Take it as a hint: Print a specific variable, not the whole array of variables.

5
  • It is also possible to only print the variable keys (though I forgot how).
    – Eyal
    Commented Jun 20, 2016 at 22:24
  • Thank you. Out of memory was the problem. Is there any maxLevels settings for dump() (something like $_kintSettings you provided for kint())?
    – PolGraphic
    Commented Jun 22, 2016 at 3:43
  • 1
    @Eyal I guess you were thinking about dump(_context|keys)
    – PolGraphic
    Commented Jun 22, 2016 at 3:44
  • Wasn't that. But if it works then it is fine as well.
    – Eyal
    Commented Jun 22, 2016 at 3:55
  • dump() uses $output = Variable::export($input) to output the variables array. It seems that there is no way to set how many level to go deep into array. Commented Jun 22, 2016 at 7:51

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.