Reputation: 1510
I want to check if a role is not granted. I have to display something only for USER but MANAGER is the hierarchy above.
To get that I am doing:
{% if is_granted('ROLE_MANAGER') %}
{% else %}
my message
{% endif %}
Which is not really nice. What can be the correct syntax for:
{% if is_NOT_granted('ROLE_MANAGER') %}
ideas?
Upvotes: 29
Views: 58047
Reputation: 1567
Or again
{% if not is_granted('ROLE_MANAGER') %}
my message
{% endif %}
Upvotes: 77
Reputation: 3085
You can also use:
{{ is_granted('ROLE_MANAGER') ? 'true message' : 'false message' }}
or to leave the true output empty:
{{ is_granted('ROLE_MANAGER') == false ? 'false message' }}
Upvotes: 3
Reputation: 39390
You can simply check as follow:
{% if is_granted('ROLE_MANAGER') == false %}
my message
{% endif %}
Hope this help
Upvotes: 30