I want to show parts of a template to specific roles.
I'm able to retrieve the user role with user.roles however I can't find a function in twig like in_array to check the roles of a user against a list of allowed roles.
my code just so far is:
{% for role in user.roles %}
{% if role == 0 or role ==7 or role == 9 %}
{# restricted content #}
{% endif %}
{% endfor %}
however the problem with this code (besides being not very elegant I think) is that if the current user has multiple roles (like admin has the root and everyone roles), the content will be shown "n" times for every assigned role.
Is there a (better) solution?
Thanks