Dynamic variables in twigs
In the form, I dynamically define the fields in the controller. Then in TWIG
I would like to use form_widget
to output the fields.
The usual approach when knowing the fields looks like below:
{{ form_widget(form.field1) }}
In this case, we cannot know if we will have in advance field1
, field2
etc. Although we have the field names in a variable named key
.
So what we would like to achieve is replace hardcoded field1
with something dynamic.
+3
source to share