对于所有 Symfony 版本,资源路径都是%kernel.root_dir%/Resources/
. 由于新的 4.0 结构将Kernel.php
intosrc/
目录,那么它是:
# 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.
覆盖资源的新约定(自 Symfony 3.4 起)
树枝模板:只需遵循约定:
templates/bundles/AcmeDemoBundle/path/to/template.html.twig
如果您要升级到 Symfony 3.4 和 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
翻译:类似于templates/
您translations/
在项目的根目录下(默认情况下):
translations/bundles/AcmeDemoBundle/messages.en.yml
注意:/bundles/AcmeDemoBundle/
子目录不是强制性的,因为翻译与捆绑无关,而是与域相关。这意味着您可以覆盖翻译,只要它位于正确的域中。