Get ROLE of a user not logged in TWIG Symfony2

后端 未结 4 1010
陌清茗
陌清茗 2020-12-14 19:28

I would like to know how can i know if a user is granted when it\'s not the current user in twig.

I use this code for the current user:

{% if is_gran         


        
4条回答
  •  抹茶落季
    2020-12-14 19:58

    You can use similar statement to the above with "not" :

    {% if not is_granted('ROLE_USER') %}
        Delete
    {% endif %}
    

    or use else statement:

    {% if is_granted('ROLE_USER') %}
        Delete
    {% else %}
        {# something else for guest user, not logged in #}
    {% endif %}
    

提交回复
热议问题