doumigu9594 2017-07-21 13:46
浏览 57
已采纳

如何在Symfony 4中覆盖第三方捆绑包的资源?

I did a fresh Symfony installation by using Symfony Flex and the new skeleton belong to the next Symfony 4 directory structure. Next, I'm going to override some resources like templates, translations, etc. from an external bundle.

I've tried to create all these paths for templates (to start) but nothing works:

  • templates/EasyAdminBundle/views/...
  • templates/Resources/EasyAdminBundle/views/...
  • app/Resources/... (just a proof from old structure)

Where should I puts my resources files to override third-party bundle resources?

  • 写回答

1条回答 默认 最新

  • dougao1106 2017-07-21 13:53
    关注

    For all Symfony versions the resources path is %kernel.root_dir%/Resources/ . As the new 4.0 structure puts the Kernel.php into src/ directory, then it is:

    # 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.
    

    New conventions to override resources (since Symfony 3.4)

    Twig Templates: Just follow the convention:

    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: Similar to templates/ you have the translations/ directory at the root of the project (by default):

    translations/bundles/AcmeDemoBundle/messages.en.yml
    

    Note: The /bundles/AcmeDemoBundle/ sub-directory is not mandatory because translations are not related to bundles, but to domains. That means that you can override translations as long as it is in the correct domain.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等