简体   繁体   中英

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

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

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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM