我使用Symfony Flex进行了全新的Symfony安装,新的骨架属于下一个Symfony 4目录结构。接下来,I'm going to override some resources来自外部捆绑包的模板,翻译等。
我试图为模板创建所有这些路径(开始),但没有任何作用:
templates/EasyAdminBundle/views/...
templates/Resources/EasyAdminBundle/views/...
app/Resources/...
(只是旧结构的证据)我应该将资源文件放在哪里以覆盖第三方捆绑资源?
答案 0 :(得分:15)
对于所有Symfony版本,资源路径为%kernel.root_dir%/Resources/
。当新的4.0结构将Kernel.php
放入src/
目录时,它就是:
# local resources directory
src/Resources/
# still works this path for local templates
src/Resources/views/
# override resources for third-party bundles
src/Resources/AcmeDemoBundle/views/ # legacy convention to override templates
src/Resources/AcmeDemoBundle/translations/ # for override both translations and validations files
src/Resources/AcmeDemoBundle/... # etc.
<强> Twig Templates 强>: 按照惯例:
templates/bundles/AcmeDemoBundle/path/to/template.html.twig
如果您要升级到Symfony 3.4&amp; 4.0并且您想使用以前的模板约定,配置您自己的Twig路径:
# app/config/config.yml (3.3) twig: paths: # Default templates directory, since 3.4+ templates: ~ # Directory convention to override bundle templates, since 3.4+ # make sure to know the actual Twig namespace for each bundle. # e.g. AcmeDemoBundle -> AcmeDemo: templates/bundles/AcmeDemoBundle: AcmeDemo
Translations:与templates/
类似,您在项目的根目录中有translations/
目录(默认情况下):
translations/bundles/AcmeDemoBundle/messages.en.yml
注意:/bundles/AcmeDemoBundle/
子目录不是是必需的,因为翻译与包无关,而与域有关。这意味着只要它在正确的域中,您就可以覆盖翻译。