# `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' => true,
// ...
));
$twig->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><pre>
{{ dump(user) }}
</pre>
</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
- Twig
- Introduction
- Installation
- Twig for Template Designers
- Twig for Developers
- Extending Twig
- Twig Internals
- Deprecated Features
- Recipes
- Coding Standards
- Tags
- autoescape
- block
- do
- embed
- extends
- filter
- flush
- for
- from
- if
- import
- include
- macro
- sandbox
- set
- spaceless
- use
- verbatim
- Filters
- abs
- batch
- capitalize
- convert_encoding
- date
- date_modify
- default
- escape
- first
- format
- join
- json_encode
- keys
- last
- length
- lower
- merge
- nl2br
- number_format
- raw
- replace
- reverse
- round
- slice
- sort
- split
- striptags
- title
- trim
- upper
- url_encode
- Functions
- attribute
- block
- constant
- cycle
- date
- dump
- include
- max
- min
- parent
- random
- range
- source
- template_from_string
- Tests
- constant
- defined
- divisible by
- empty
- even
- iterable
- null
- odd
- same as