Symfony config.yml无法加载Twig扩展

时间:2015-06-13 19:39:01

标签: php symfony twig

我的config.yml如下:

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }

framework:
    #translator:      { fallback: %locale% }
    secret:          %secret%
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_proxies: ~
    session:         ~
    fragments:       ~
    http_method_override: true

我收到错误:

 'The service definition "templating.engine.twig" does not exist.'

但是Twig扩展名在/vendor/twig文件夹中。我还需要做些什么才能让它发挥作用?

1 个答案:

答案 0 :(得分:1)

您必须注册TwigBundle并进行配置。在Symfony标准版中可以看到一个例子:

app/config/config.yml

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

app/AppKernel.php

new Symfony\Bundle\TwigBundle\TwigBundle(),