0

I'm trying to work with a loop in a Controller (in Symfony4) to create a form, with different lines

for ($i=1 ; $i<=$nblig ; $i++) { $formBuilder ->add('date'.$i, DateType::class) -> (...) } 

The form works fine (I can dump it). I need a similar loop, when I try to render that form with Twig :

{% for i in 1..nblig %} {{ form_widget(form.date ~ i)) }}{% endfor %} 

And I don't know how to concatenate the field name date, with the var i.

Thanks for your help

1 Answer 1

2

You are now combining the value of form.date with i, what you want, you can use either the array notation or use attribute for

{{ form_widget(form['date' ~ i]) }} 

{{ form_widget(attribute(form, 'date'~i)) }} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.