简体   繁体   中英

Twig_Error_Syntax: The function “code” does not exist (for production environment)

I'm new to php and Symfony and I created my bundle using php app/console command following the tutorial from Symfony. There is 2 environment, dev and prod and I have been using dev since the beginning without problem, with Symfony's "Code behind this" and the sql and form profilers showing at the bottom of every page that is showing.

When I switch to prod by using app.php instead of app_dev.php, all the code breaks. One that is very persistant is the one in Twig: the function "code" does not exist. Here is the code in twig:

{% set code = code(_self) %}

I've tried wrapping it inside if defined as documented in Twig's website, but the error persist:

{% if _self is defined and code(_self) is defined %}
{# if code is defined #}
{% set code = code(_self) %}
{% endif %}

both way of checking if defined doesn't have any effect at all. I've cleared cache and even restarted my machine but the error persist. However, if I switch back to using app_dev.php, everything works but I still see the profiler console and the code behind this. I don't want to remove the code as the profiler view is very useful in development. Any suggestion?

The problem in that {{code }} is not a twig extension or not provided by twig,This extension is provided by 'Demobundle' for more information see this

Twig code is not working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM