SonataAdmin, add menu to the left

I am working on Symfony2 and SonataAdminBundle.

I need to know how to add a menu to the left side of my dashboard? Like on the screen:

enter image description here

I need to have a Dashboard block on the left side of the page (in dark gray on my screen). How can i do this?

you can see on the SonataAdmin demo http://demo.sonata-project.org/admin/dashboard , admin admin, apssword admin

+8
symfony sonata-admin
source share
6 answers

http://blog.eike.se/2014/03/custom-page-controller-in-sonata-admin.html

This post has helped me.

expand template

vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig 

blocking block

 {% extends 'SonataAdminBundle::standard_layout.html.twig' %} {% block side_bar_after_nav %} YOUR CUSTOM MENU {% endblock %} 
+8
source share

I just added ROLE_SONATA_ADMIN to ROLE_ADMIN in security.yml:

 security: role_hierarchy: ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN] 

and he appeared, finally. For more information check this out: https://github.com/sonata-project/SonataAdminBundle/issues/2321

+7
source share

The first thing to do is open this file along this path:

\ wamp \ www \ YourProject \ vendor \ sonata-project \ admin-bundle \ Resources \ view \ standard_layout.html.twig

Then find: ROLE_SONATA_ADMIN (using Ctrl + F), and then change to the role that you use to enter the admin control panel for me. I use ROLE_ADMIN , then save the file, close it, check the admin control panel, you will find exactly what you are looking for.

hope it works

+6
source share

Well, if you want to use the automatic menu created by the sonata, you can use these steps to reach the point:

Decision

  • override default sonata twig file with config.yml

     sonata_admin: templates: layout: ::layout.html.twig 
  • your ::layout.html.twig :

     {% extends 'SonataAdminBundle::standard_layout.html.twig' %} {% block side_bar_nav %} {{ knp_menu_render('sonata_admin_sidebar', {template: sonata_admin.adminPool.getTemplate('knp_menu_template')}) }} {% endblock %} 

Why is this decision?

since by default SonataAdminBundle::standard_layout.html.twig checks the user for ROLE_SONATA_ADMIN permission (and you cannot use sonata user bundle ), you need to redefine the rights check process, which is by default:

 {% block side_bar_nav %} {% if app.user and is_granted('ROLE_SONATA_ADMIN') %} {{ knp_menu_render('sonata_admin_sidebar', {template: sonata_admin.adminPool.getTemplate('knp_menu_template')}) }} {% endif %} {% endblock side_bar_nav %} 

I think this is the easiest way to use the navigation buttons on the left sidebar.

+2
source share

finally,

They seem to have updated the sonata admin package doc code,

take a look at this => http://sonata-project.org/bundles/admin/master/doc/reference/architecture.html

or using a user package:

http://sonata-project.org/bundles/user/master/doc/reference/user_dashboard.html

hope it works

0
source share

Do two things:

  • Create a template called standard_layout.html.twig in your Resources/views folder. Add this to this template:

    {% extends 'SonataAdminBundle::standard_layout.html.twig' %} {% block side_bar_nav %} //add your code here {% endblock side_bar_nav %}

PS: Look at the side_bar_nav block in vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig for direction

  1. In app/config/config.yml (or wherever your configuration file is located), add:

sonata_admin: templates: layout: YourBundle::standard_layout.html.twig

I recommend using YourBundle:Admin:standard_layout.html.twig to organize all your admin templates in one Admin folder. You will need to change the location of the template in step 1, respectively

0
source share

All Articles