I don't know why it shows this error
The function "dump" does not exist in twig file
while I have already writen in config.yml
file:
services:
product_store.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }
and in twig file I try to dump with:
{{ dump(product) }}
The answer from lifo encourages you to use the debug
tag, but the debug
tag {% debug product %}
was deprecated in Twig 1.5 and replaced with the dump
function {{ dump(product) }}
.
The proper extension to enable as of Symfony Standard Edition 2.0.9 is Twig_Extension_Debug
and should be added to app/config/config_dev.yml
so it is only loaded in the dev environment:
services:
twig.extension.debug:
class: Twig_Extension_Debug
tags: [{ name: 'twig.extension' }]
You should then be able to use {{ dump(product) }}
in your templates.
If a problem still exists, you can try a few things:
Use php app/console container:debug twig.extension.debug --env=dev
to ensure the dependency injection container is properly picking up your service definition.
[container] Information for service twig.extension.debug
Service Id twig.extension.debug
Class Twig_Extension_Debug
Tags
- twig.extension ()
Scope container
Public yes
Synthetic no
Required File -
Open the compiled dependency injection container class for your dev environment and search for Twig_Extension_Debug
to see if any other service was already defined to use it. This file lives at app/cache/dev/appDevDebugProjectContainer.php
Ensure the parameter %kernel.debug%
is true.
Ensure you're using Twig 1.5 or later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With