Twig’s {{ dump() }} function is very handy to inspect a variable inside a template. But without the right package installed, the output is unreadable. Here is how to get a clean, collapsible display like this one:

Install the DebugBundle
The nice output comes from Symfony’s VarDumper component, enabled by the DebugBundle. Install it as a development dependency:
composer require --dev symfony/debug-bundle
With Symfony Flex, the debug alias also works:
composer require --dev debug
Using it in a template
Two syntaxes are available:
{# affiche le contenu d'une variable #}
{{ dump(user) }}
{# ou, sous forme de balise, plusieurs variables à la fois #}
{% dump user, articles %}Good to know
Since the bundle is installed with --dev, the dump() function outputs nothing in production: no risk of leaking data if a call is left behind in a template.
