Override bundle template from another bundle in Symfony 4/5

前端 未结 3 1972
轻奢々
轻奢々 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:39

    Here's a more comprehensible example

    Let's start with making some assumptions

    Your bundle's name: AcmeBundle

    Bundle you want to override: FOSUserBundle

    Run command php bin/console debug:twig and find the namespace of the bundle you want to override. In this case it's @FOSUser.

    Your bundle extension should look like this

    loadFromExtension('twig', array(
                'paths' => array(
                    '%kernel.project_dir%/src/AcmeBundle/Resources/FOSUserBundle/views' => 'FOSUser', // You use the namespace you found earlier here. Discard the `@` symbol.
                ),
            ));
        }
    }
    

    Now you can create src/AcmeBundle/Resources/FOSUserBundle/views/Security/login.html.twig to override the login template of FOSUserBundle.

    This was just an example for FOSUserBundle. You can change bundle names depending on what you're trying to override.

提交回复
热议问题