Search code examples
symfonytwigsymfony4readonly

the readonly value depends on a variable symfony4


well I want the readonly proprety to have a value depending on a variable.

My idea is like this :

sending the variable(which is a boolean) as a parameter when rendering.

return $this->render('responsable/uneInscription.html.twig', [
  'form'     => $form->createView(),
  'readonly' => $readonly,
]);

and use the variable like this :

{{ form_row(form.id_diplome.niveau, {'attr': {'class' : 'form-control' ,'readonly': {{readonly}} } }) }}

but it just doesn't work, I always get a readonly field

I am new to symfony so I don't even know if it is possible


Solution

  • You're using the readonly variable wrong. You're printing its value out with {{ readonly }}, rather than using it directly.

    The following should work:

    {{ form_row(form.id_diplome.niveau, {'attr': {'class': 'form-control', 'readonly': readonly }}) }}