I'm working on Symfony2 and SonataAdminBundle.
I need to know how to add a menu in the left part of my dashboard ? Like in the screen :
I need to have the Dashboard block in the left part on the page (in dark-grey on my screen).. how can i do that ?
you can see on the demo of SonataAdmin http://demo.sonata-project.org/admin/dashboard , login admin, apssword admin
http://blog.eike.se/2014/03/custom-page-controller-in-sonata-admin.html
this post helped me.
extend template
vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig
override block
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block side_bar_after_nav %}
YOUR CUSTOM MENU
{% endblock %}
I've just added ROLE_SONATA_ADMIN to ROLE_ADMIN in security.yml:
security:
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
and it shown up, finaly. For more info check this: https://github.com/sonata-project/SonataAdminBundle/issues/2321
The first thing to do is to open this file in this path:
\\wamp\\www\\YourProject\\vendor\\sonata-project\\admin-bundle\\Resources\\view \\standard_layout.html.twig
Then look for : ROLE_SONATA_ADMIN
(using Ctrl+F) then changed to the role that you are using to log in to your admin dashboard for me I'm using ROLE_ADMIN
, then save the file, close it, check your admin dashboard, you will find exactly what you look for.
hope it will works
well, if you want to use the automatic menu generated by sonata you can use this steps to reach the point:
Solution
override the default sonata layout twig file from 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 this solution?
since the default SonataAdminBundle::standard_layout.html.twig
checks the user to have the ROLE_SONATA_ADMIN
permission (and you might not using sonata user bundle
), you need to override permission checking 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 navigation buttons on left sidebar.
okay finally,
it seems they updated sonata admin bundle doc,
take a look at this => http://sonata-project.org/bundles/admin/master/doc/reference/architecture.html
or with user bundle :
http://sonata-project.org/bundles/user/master/doc/reference/user_dashboard.html
hope it will works
Do two things:
Create a template called standard_layout.html.twig
in your custom bundle's Resources/views
folder. Add this to that template:
{% extends 'SonataAdminBundle::standard_layout.html.twig' %} {% block side_bar_nav %} //add your code here {% endblock side_bar_nav %}
PS: Look at block side_bar_nav
in vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig
for direction
app/config/config.yml
(or wherever your config file is), 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 into a single Admin
folder. You'd need to change the location of the template in step 1 accordingly
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.