Override bundle template from another bundle in Symfony 4/5

前端 未结 3 1963
轻奢々
轻奢々 2021-02-09 07:03

because bundle inheritance is deprecated since Symfony 3.4 and will be removed in 4.0, I\'m finding a new solution. I have:

  • Application
  • FooBundle
3条回答
  •  孤独总比滥情好
    2021-02-09 07:44

    So I have recently needed same functionality and with help from comment @NicoHasse I managed to make working example

    In your bundle bundle extension class you need to implement PrependExtensionInterface and then you can modify twig paths. Then you need to know original namespace your you need to override (php bin/console debug:twig).

    You can confirm its working with twig debug command where you should see your path at first place of that namespace.

    class YourExtensionClass extends Extension implements PrependExtensionInterface
    {
        public function prepend(ContainerBuilder $container)
        {
            $container->loadFromExtension('twig', [
                'paths' => [
                    '%kernel.project_dir%/vendor/xx/yy/zzz' => 'OriginalVNamespace',
                ]
            ]);
    

提交回复
热议问题