FOSUserBundle template override not working with Symfony Flex

Viewed 2626

I have a problem with Symfony Flex and FOSUserBundle. I can't override default FOSUserBundle templates. I tried to do everything following the Symfony documentation, tutorials and nothing works. It's just like Twig won't take my layout.html.twig to render instead of default FOSUserBundle.

Templates dir tree looks like it should following new Symfony Flex structure:

- templates
   - default
   - FOSUserBundle
      - views
         - layout.html.twig
   - base.html.twig

Maybe anyone has encountered similar problem with Symfony Flex.

7 Answers

Pull request that was merged in Symfony 3.4 at https://github.com/symfony/symfony/pull/24179 and available since 3.4-BETA1 and 4.0-BETA1 specifies that you need to place the template at templates/bundles/FOSUserBundle/layout.html.twig. PR description mentions exactly this usecase as its example.

In Symfony 3.3, it should work by placing the template in src/Resources/FOSUserBundle/views/layout.html.twig

I don't anderstand why that doesn't work for me with symfony 4.0.8 in: - templates - FOSUserBundle - layout.html.twig

but it works in src - Resources - FOSUserBundle - views - layout.html.twig

I have a similar problem with symfony4 and fosUserBundle per to https://symfony.com/doc/current/templating/overriding.html, for registration_content overriding i put my template file in templates\bundles\FOSUserBundle\Registration\register_content.html.twig and it ready to works hope work for you

I'm going to drop my answer here, because I am in a constant uphill battle with this bundle.

I copied the desired templates from the bundle in vendor and at first put them in,

project_root/src/Resources/FOSUserBundle

However after reading the documentation, it seems that it should be placed in project_root/templates/bundles/name_of_bundle/*.

However that didn't work because FOSUserBundle file structure is not adhering to symfonys conventions, you have to move things out of the views folder.

So rather than project_root/templates/bundles/name_of_bundle/views, move everything out of the views folder and into the parent name_of_bundle folder.

In your custom User bundle you must decalre the parent bundle

use Symfony\Component\HttpKernel\Bundle\Bundle;

class YourNameSpaceUserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

Note: Symfony Flex is alpha software; use it at your own risk

- templates
 - FOSUserBundle
      - layout.html.twig

Work for me too in Symfony 4.0.8 !

Related