Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override SonataUserBundle templates

I've installed SonataAdminBundle and SonataUserBundle and I'm trying to override some twig templates. I've done succesfully with all except with user_block.html.twig

This is my proyect ../app/Resources/ directory structure:

Resources/
├── ApplicationSonataUserBundle
│   └── views
│       ├── Admin
│       │   └── Core
│       │       └── user_block.html.twig   <--- it doesn't work
│       ├── layout.html.twig
│       ├── Profile
│       │   ├── action.html.twig
│       │   ├── edit_authentication.html.twig
│       │   ├── edit_profile.html.twig
│       │   └── show.html.twig
│       └── Security
│           └── login.html.twig
├── SonataAdminBundle
│   └── views
│       └── standard_layout.html.twig
└── TwigBundle
    └── views
        └── Exception
            └── error.html.twig

Also I've tried put it under SonataAdminBundle or SonataUserBundle directory but nothing, it didn't work for me.

How can I override user_block template?

Thanks

like image 341
xabi82 Avatar asked Oct 02 '22 02:10

xabi82


2 Answers

Alternatively, you can use the configuration, like this :

sonata_admin:
    templates:
        layout:                 
        user_block: '::Admin/user_block.html.twig'

And then put your template here : app/Resources/views/Admin/user_block.html.twig

like image 171
greg0ire Avatar answered Oct 13 '22 11:10

greg0ire


Answer

The directory file structure shown before works fine. I've solved the problem just adding the necessary js and css on standard_layout.html.twig

{% block stylesheets %}
            ...

            <!-- custom stylesheets -->
            <link rel="stylesheet" href="{{ asset('bundles/mybundle/css/mycssfile.css') }}" media="all">

{% endblock %}

{% block javascripts %}
            ...
            <!-- custom js -->
            <script src="{{ asset('bundles/mybundle/js/myscriptfile.css') }}"></script>

{% endblock %}
like image 29
xabi82 Avatar answered Oct 13 '22 10:10

xabi82