I add for template (index.html.twig) simply:
{{ dump(product) }}
and i have error:
The function "dump" does not exist in AcmeStoreBundle:Default:index.html.twig at line 2
Why this function is not enable, and how can i enable this?
I add for template (index.html.twig) simply:
{{ dump(product) }}
and i have error:
The function "dump" does not exist in AcmeStoreBundle:Default:index.html.twig at line 2
Why this function is not enable, and how can i enable this?
You need to configure the debugging extension:
# app/config/config.yml
services:
acme_hello.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }
Per the link mentioned above, Twig debugging is set to work by default in Symfony 2.5+ running Twig 1.16+, and the custom service definition is not necessary. See this answer for more details.
Symfony 2.7+ UPDATE:
The DebugBundle allows greater integration of the component into the Symfony full-stack framework. It is enabled by default in the dev and test environment of the Symfony Standard Edition.
Check the VarDumper component and its integration on Twig.
OLD ANSWER:
I would like to suggest a non-native solution. You'll need a third-party bundle, but the final result will be great!
Improvements to the dump
version:
ldd()
, which is an alias for the classic "dump and die"php app/console ladybug:dump "Symfony\Component\HttpFoundation\Request"
)Here the links:
When you configure it like @meze said, you can display all custom variables:
<h1>Variables passed to the view:</h1>
{% for key, value in _context %}
{% if key starts with '_' %}
{% else %}
<pre style="background: #eee">{{ key }}</pre>
{{ dump(value) }}
{% endif %}
{% endfor %}
You can use my simple plugin to convenient inspect your variables: