3
votes

When I was working on an older project (Symfony 3.2), the {{ dump(var) }} in twig templates was displaying just fine (with style and expand/collapse capabilities). But on my recent project (Symfony 4), the dump function in twig is displaying the text only.

I looked in the docs, GitHub issues for both Symfony and Twig and in SO without any success.

Docs:

Is there anything that have changed which I didn't see?

Edit: I got the desired result using dump() in PHP (got the syntax color & collapse/expand), but I still don't understand why it is not working for twig like it is in older Symfony version. I must be missing something...

2
Are u perhaps working on another server as well, which does not has xdebug installed?DarkBee
@DarkBee, it's on the same environment (local). Only the projects creation differs.Marc-André
When looking for the Twig documentation, it says that you do not need to add the <pre> tag if you activated xdebug. In fact, just using {{ dump() }} does create the <pre> tag by itself (so you get readable lines instead of one big block), so I guess it's fine on the xdebug side?Marc-André
Does the symfony/var-dumper component is enabled ?BENARD Patrick
@candybeer Can you please add your comment as an answer so I can award you with the bounty? Thanks.Marc-André

2 Answers

2
votes

As specified in the doc,the component has to be installed before using it :

Doc : https://symfony.com/doc/current/components/debug.html

Command :

composer require symfony/debug

You've to check if it's well enabled..

1
votes

Thanks to @candybeer for leading me on the way to go.

Just add the debug-pack package to the project (which includes the symfony\debug-bundle):

composer require debug --dev

Or

Simply add the debug-bundle which is required as said in the other SO question comments:

composer require symfony/debug-bundle


Found in this SO question: Symfony 4: Var-dumper not working properly :

The dump()was not working in twig and was throwing an error, but the answer told to also install the debug package, which made it work for the OP. Giving it a try myself, I am now able to dump via twig with the standard style and ability to collapse/expand nodes.

Like said in the comments (and in the var-dumper documentation), the var-dumper package requires the debug-bundle package to work in symfony.

Once again, many thanks to you @candybeer!