8

我使用 Symfony Flex 进行了全新的 Symfony 安装,新的骨架属于下一个 Symfony 4 目录结构。接下来,将从外部包中覆盖一些资源,如模板、翻译等。

我尝试为模板创建所有这些路径(开始),但没有任何效果:

  • templates/EasyAdminBundle/views/...
  • templates/Resources/EasyAdminBundle/views/...
  • app/Resources/...(只是旧结构的证明)

我应该把我的资源文件放在哪里来覆盖第三方捆绑资源?

4

1 回答 1

16

对于所有 Symfony 版本,资源路径都是%kernel.root_dir%/Resources/. 由于新的 4.0 结构将Kernel.phpintosrc/目录,那么它是:

# 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/子目录不是强制性的,因为翻译与捆绑无关,而是与域相关。这意味着您可以覆盖翻译,只要它位于正确的域中。

于 2017-07-21T13:53:29.213 回答