2

I am working with the views-view-unformatted.html.twig file, and I am trying to use the following code.

{{ dump(row.content | keys) }}

The returned value is the following.

/var/www/html/example_site/vendor/twig/twig/lib/Twig/Extension/Debug.php:60:
array (size=5)
  0 => string '#theme' (length=6)
  1 => string '#view' (length=5)
  2 => string '#options' (length=8)
  3 => string '#row' (length=4)
  4 => string '#field_alias' (length=12)

With {{ dump(row.content['#row'] | keys) }} I get the following.

/var/www/html/example_site/vendor/twig/twig/lib/Twig/Extension/Debug.php:60:
array (size=0)
  empty

Based on it being empty, I assume it is not an array and proceed to use {{ dump(row.content['#row']) }}. When I do this I get a 504 Gateway Timeout error. max_execution_time is set to 30.

How do I dump a variable that is too big for dump(var)?

  • why are you debugging in template and not in preprocess with xdebug? – user21641 Aug 23 '17 at 21:01
  • Don't have xdebug configured on the server. – FatGuyLaughing Aug 24 '17 at 22:13
2

As a workaround, until Kint will be configurable via UI see #2405179, edit modules/devel/kint/kint/config.default.php and set $_kintSettings['maxLevels'] to a lower number (the default is 7).

Try using 4. This will limit the depth of the array that gets dumped.

  • 1
    sometimes the solution to a problem, is to just prevent it from happening, right? – Pierre.Vriens Aug 24 '17 at 20:53
0

A good way to get around twig's limits is to add the preprocess function referenced in the twig debug HTML comments. Then use kint to dump the information.

If you are doing something that is called a lot of times and kint is overflowing memory, just add a global counter and limit the output to one or two items. Something like:

$mymod_$kint_count = 0;
function mymod_preprocess_page(&$variables) {
  global $mymod_kint_count;
  if ( $mymod_kint_count++ < 1 ) {
    kint($variables);
  }
}

Note: You will need the kint module and dev enabled for this to work.

0

Use of {{ dsm(row.content) }} will solve your problem. This code takes a little time irrespective of how much data, displays it all.

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.