I'm having trouble getting the is_granted function in twig to test a variable. In this case, I am testing if the current user is granted the role contained in the form.roles, but unfortunately the is_granted test will ONLY accept a string, and passing a variable is always returning false.
<div class="form-group well">
{{ form_label(form.roles) }}
{% for role in form.roles %}
{{ role.vars.value|trim }}{% if is_granted('{{ role.vars.value }}') %}
<div class="row marketing ">
<div class="col-sm-6">
{{ form_label(role) }}
</div>
<div class="col-sm-6">
{{ form_widget(role, {"attr": {"class": "form-control"}} ) }}
</div>
</div>
{% endif %}
{% endfor %}
</div>
I have tried to filter the output to ensure that it is a string, without success, and the quotes in {% if is_granted('{{ role.vars.value }}') %} MUST be there as the system errors if they are not included.
Output of this code is:
Allocated Roles ROLE_SYSTEM_ADMIN ROLE_REGISTRAR ROLE_ADMIN ROLE_PRINCIPAL ROLE_HEAD_TEACHER ROLE_TEACHER ROLE_STUDENT ROLE_PARENT ROLE_USER
Any idea on how I can get the is_granted to test from the value given?