💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# `dump` New in version 1.5: The `dump` function was added in Twig 1.5. The `dump` function dumps information about a template variable. This ismostly useful to debug a template that does not behave as expected byintrospecting its variables: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>{{ dump(user) }} </pre></div></td></tr></table> Note The `dump` function is not available by default. You must add the`Twig_Extension_Debug` extension explicitly when creating your Twigenvironment: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3 4 5</pre></div></td><td class="code"><div class="highlight"><pre>$twig = new Twig_Environment($loader, array( 'debug' =&gt; true, // ... )); $twig-&gt;addExtension(new Twig_Extension_Debug()); </pre></div></td></tr></table> Even when enabled, the `dump` function won't display anything if the`debug` option on the environment is not enabled (to avoid leaking debuginformation on a production server). In an HTML context, wrap the output with a `pre` tag to make it easier toread: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3</pre></div></td><td class="code"><div class="highlight"><pre>&lt;pre&gt; {{ dump(user) }} &lt;/pre&gt; </pre></div></td></tr></table> Tip Using a `pre` tag is not needed when [XDebug](http://xdebug.org/docs/display) [http://xdebug.org/docs/display] is enabled and`html_errors` is `on`; as a bonus, the output is also nicer withXDebug enabled. You can debug several variables by passing them as additional arguments: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>{{ dump(user, categories) }} </pre></div></td></tr></table> If you don't pass any value, all variables from the current context aredumped: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre>{{ dump() }} </pre></div></td></tr></table> Note Internally, Twig uses the PHP [var_dump](http://php.net/var_dump) [http://php.net/var_dump] function. ### Arguments - `context`: The context to dump