Search code examples
htmlsymfonysonata-adminsymfony-sonatasonata

How to add a button to nav-bar?


How can I add another button/dropdown to the navbar in sonata admin listing template for my MapAdmin class?

Add button in sonata admin

I just want this button in one admin class.


Solution

  • You have to override the default template (layout: 'SonataAdminBundle::standard_layout.html.twig') with your own in coding your logique here

    Here is an extract of existing code :

                                            {% block sonata_admin_content_actions_wrappers %}
                                                {% if _actions|replace({ '<li>': '', '</li>': '' })|trim is not empty %}
                                                    <ul class="nav navbar-nav navbar-right">
                                                    {% if _actions|split('</a>')|length > 2 %}
                                                        <li class="dropdown sonata-actions">
                                                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ 'link_actions'|trans({}, 'SonataAdminBundle') }} <b class="caret"></b></a>
                                                            <ul class="dropdown-menu" role="menu">
                                                                {{ _actions|raw }}
                                                            </ul>
                                                        </li>
                                                    {% else %}
                                                        {{ _actions|raw }}
                                                    {% endif %}
                                                    </ul>
                                                {% endif %}
                                            {% endblock sonata_admin_content_actions_wrappers %}