how to render dynamic menus based on logged user role on symfony2 how to render dynamic menus based on logged user role on symfony2 symfony symfony

how to render dynamic menus based on logged user role on symfony2


You can achieve this at the view level too. In the template, check the active user's role and hide/show menus depending on the role

{% if is_granted('ROLE_ADMIN') and not is_granted('ROLE_USER') %}//Show admin stuff{% else if is_granted('ROLE_USER') %}//Show user stuff{% endif %}


If you really want to use the same template for both and not have logic in the template, you can pass parameters to the render method to provide the elements that will be present in your menu.