Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Get User Role in Twig

I have one question,

How can i get User role in Symfony2 Twig.

I Had looking around but I couldn't find it.

Please help, or clue..

Thanks before.

Hendrawan

like image 871
hendra1 Avatar asked Jun 24 '14 10:06

hendra1


2 Answers

A simpler option could be to test the role since you have to define them in security.yml :

{% if is_granted('ROLE_ADMIN') %}
    Administrator
{% elseif is_granted('ROLE_USER') %}
    User
{% else %}
    Anonymous
{% endif %}
like image 179
Ivan Gabriele Avatar answered Oct 15 '22 18:10

Ivan Gabriele


you can scan your collection roles of User:

{% for role in app.user.roles %}
{{ role }} <br> 
{% endfor %}
like image 34
rapaelec Avatar answered Oct 15 '22 18:10

rapaelec