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?
Or again
{% if not is_granted('ROLE_MANAGER') %}
my message
{% endif %}
You can simply check as follow:
{% if is_granted('ROLE_MANAGER') == false %}
my message
{% endif %}
Hope this help
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' }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.