Twig:如果 is_granted('ROLE_MANAGER') 检查未被授予

Twig: if is_granted('ROLE_MANAGER') check is not granted

我想检查是否未授予角色。我必须只为 USER 显示一些内容,但 MANAGER 是上面的层次结构。

为了实现我正在做的事情:

{% if is_granted('ROLE_MANAGER') %}
{% else %}
      my message 
{% endif %}

这不是很好。什么是正确的语法:

{% if is_NOT_granted('ROLE_MANAGER') %} 

想法?

您可以简单地检查如下:

 {% if is_granted('ROLE_MANAGER') == false %}
                  my message 
 {% endif %}

希望对您有所帮助

您还可以使用:

{{ is_granted('ROLE_MANAGER') ? 'true message' : 'false message' }}

或将真实输出留空:

{{ is_granted('ROLE_MANAGER') == false ? 'false message' }}

或再次

{% if not is_granted('ROLE_MANAGER') %}

   my message 
{% endif %}