How to use multiple role in a branch (Symfony2)

I have these 3 roles

1. ROLE_ADMIN 2. ROLE_SAMPLE 3. ROLE_USER 

This file is my branch

 {% if is_granted('ROLE_ADMIN') %} <a href="...">Delete</a> {% endif %} 

I need to show the delete link for ROLE_ADMIN as well as ROLE_SAMPLE
how do i get this? above code should show delete link only for ROLE_ADMIN
how to add another role ( ROLE_SAMPLE ) in this

+6
source share
2 answers

see this link: Symfony2 and Twig sidebar

 {% if is_granted('ROLE_ADMIN') or is_granted('ROLE_SAMPLE') %} <a href="...">Delete</a> {% endif %} 
+9
source

At least with Symfony 3.2.8, you can use an array to enumerate roles. Therefore, this should work:

 {% if is_granted(['ROLE_ADMIN', 'ROLE_SAMPLE']) %} <a href="...">Delete</a> {% endif %} 

I do not know when this was added, but I prefer to use multiple calls with or.

+3
source

Source: https://habr.com/ru/post/952959/


All Articles