如何覆盖 Symfony 4 中第三方包的资源?
How can I override resources for Third-Party bundles in Symfony 4?
我使用 Symfony Flex 重新安装了 Symfony,新框架属于下一个 Symfony 4 目录结构。接下来,I'm going to override some resources喜欢来自外部包的模板、翻译等。
我已经尝试为模板创建所有这些路径(开始)但没有任何效果:
templates/EasyAdminBundle/views/...
templates/Resources/EasyAdminBundle/views/...
app/Resources/...
(只是旧结构的证明)
我应该将我的资源文件放在哪里以覆盖第三方包资源?
对于所有 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.
覆盖资源的新约定(自 Symfony 3.4 起)
Twig Templates:
只需遵循约定:
templates/bundles/AcmeDemoBundle/path/to/template.html.twig
If you are upgrading to Symfony 3.4 & 4.0 and you want to use the previous templates conventions, configure your own Twig's paths:
# 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/
子目录 不是 强制性的,因为翻译与包无关,而是与域相关。这意味着您可以覆盖翻译,只要它在正确的域中即可。
我使用 Symfony Flex 重新安装了 Symfony,新框架属于下一个 Symfony 4 目录结构。接下来,I'm going to override some resources喜欢来自外部包的模板、翻译等。
我已经尝试为模板创建所有这些路径(开始)但没有任何效果:
templates/EasyAdminBundle/views/...
templates/Resources/EasyAdminBundle/views/...
app/Resources/...
(只是旧结构的证明)
我应该将我的资源文件放在哪里以覆盖第三方包资源?
对于所有 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.
覆盖资源的新约定(自 Symfony 3.4 起)
Twig Templates: 只需遵循约定:
templates/bundles/AcmeDemoBundle/path/to/template.html.twig
If you are upgrading to Symfony 3.4 & 4.0 and you want to use the previous templates conventions, configure your own Twig's paths:
# 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/
子目录 不是 强制性的,因为翻译与包无关,而是与域相关。这意味着您可以覆盖翻译,只要它在正确的域中即可。