Q:

Dynamic variables in Twigs

In a form, I dynamically define the fields in a controller. Then in the TWIG I would like to use form_widget to output the fields.
The normal approach, when knowing the fields is like shown bellow:
{{ form_widget(form.field1) }}

In this case, we cannot know whether we will have a field1, field2, etc. on beforehand. Though we have the field names in a variable called key.
So what we would like to achieve is replace the hardcoded field1 by something dynamic. 

A:

You can do something like
{{ form_widget(form[key]) }}

