Question

I'm trying to use Twig (inside Symfony2) to debug a variable that contains a multidimensional array, yet it only outputs up to three arrays deep:

array
  'Coating' => 
    array
      'type' => string 'single' (length=6)
      'data' => 
        array
          0 => 
            array
              ...
          1 => 
            array
              ...
          2 => 
            array
              ...

Whereas a print_r would generate

Array
(
    [Coating] => Array
        (
            [type] => single
            [data] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [selectable] => 1
                            [name] => Front
                        )

                    [1] => Array
                        (
                            [id] => 7
                            [selectable] => 1
                            [name] => Back
                        )

                    [2] => Array
                        (
                            [id] => 13
                            [selectable] => 1
                            [name] => Both Sides
                        )

                )

        )

)

The reason I'd like Twig to do the debugging is that printing code prior to my template being rendered completely jumbles the output of a given page -- I'd like to print the data where it is easily read.

I don't understand why a "debug" would truncate data...

Edit: The debugging is through the use of {% debug foobar %} with that tag enabled through the inclusion of the following in my app's configuration:

services:
  twig.extension.debug:
    class: Twig_Extensions_Extension_Debug
    tags: [ { name: 'twig.extension' } ]
Was it helpful?

Solution

I just read the source code of the twig debug extension (class Twig_Extensions_Node_Debug) and it doesn't truncate the var_dump. It is probably xdebug that is truncating: I cite a comment on the var_dump php.net documentation:

Keep in mind if you have xdebug installed it will limit the var_dump() output of array elements and object properties to 3 levels deep.

To change the default, edit your xdebug.ini file and add the folllowing line: xdebug.var_display_max_depth=n

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top