I have a twig template using Symfony3 like the follwing:
{% if app.environment == 'dev' %}
{{ dump(students) }}
{% endif %}
But in the 'prod' environment it throws this error, shown in the var/logs/prod.log file:
[2016-05-18 21:28:28] request.CRITICAL: Uncaught PHP Exception Twig_Error_Syntax: "Unknown "dump" function in "search/search_pet_results.html.twig" at line 13." at /var/www/html/petition/vendor/twig/twig/lib/Twig/ExpressionParser.php line 573 {"exception":"[object] (Twig_Error_Syntax(code: 0): Unknown \"dump\" function in \"search/search_pet_results.html.twig\" at line 13. at /var/www/html/petition/vendor/twig/twig/lib/Twig/ExpressionParser.php:573)"} []
Any suggestions for my twig template? Don't know what to try, because this is "supposed" to work.
In a Twig template, you can use the dump utility as a function or a tag: {% dump foo. bar %} is the way to go when the original template output shall not be modified: variables are not dumped inline, but in the web debug toolbar; on the contrary, {{ dump(foo.
Twig is a modern template engine for PHP Fast: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum. Secure: Twig has a sandbox mode to evaluate untrusted template code.
Twig uses a central object called the environment (of class \Twig\Environment ). Instances of this class are used to store the configuration and extensions, and are used to load templates. Most applications create one \Twig\Environment object on application initialization and use that to load templates.
The dump function is not available by default, as described in the doc here . You must set the debug flag to true in order to enable on the environment. The flag is located in the config.yml files, under the twig section. Usually the value is taken from the kernel value.
So probably your config.yml is same as follow:
config.yml
# Twig Configuration
twig:
debug: "%kernel.debug%"
Try modify as follow in order to enable in all the environment:
config.yml
# Twig Configuration
twig:
debug: true
Hope this help
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