Symfony 3.4 扩展在迁移后不起作用

Symfony 3.4 Extends not working after migration

我将 symfony 从 2.7 版迁移到 3.4 版

除一件事外,一切都很好。 Twig 文件无法正常工作,错误消息是:

Unable to find template "::layout.html.twig" (looked into: vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/views/Form, vendor\knplabs\knp-menu\src\Knp\Menu/Resources/views) in abcdBundle::layout.html.twig at line 3.

树枝代码是:

{% extends "::layout.html.twig" %}

我想加载本地化的布局到 app/Resources/views/layout.thml.twig。 我也试过这段代码:{% extends "layout.html.twig" %} 没有 :: 同样的麻烦。

位置文件:

app/
    Resources/
        views/
            layout.html.twig // it don't find this twig

src/
    ab/
        cdBundle/
            Ressources/
                views/
                    layout.html.twig // error into this file

我更新了 config.yml 文件以添加:

twig:
    paths:
        '%kernel.project_dir%/app/Resources/views': app

这在 bin/console debug:twig[=] 的“Loader Paths”中添加了“Namespace@app 14=]

现在,当我使用 {% extends "@app/layout.html.twig" %} 它工作正常。

感谢@Cerad 的帮助,非常感谢

如果你想让你的项目更安全并为将来迁移到 Symfony 4 做好准备 – 考虑将你所有的 Resources 移出 app/ 目录。

你可以找到更多,即。在这里:

http://fabien.potencier.org/symfony4-directory-structure.html