简体   繁体   中英

symfony twig variables in form field

I have a number of fields in my FromType file that have name :

//formType.php
for($i=0;$i<N;$i++){
 ->add('matricola_'.$i, TextType::class, array(
/*....*/
 ->add('tipologia_'.$i, TextType::class, array(
/*....*/
 ->add('esame_'.$i, TextType::class, array(
/*....*/
}

I don't understand in twig file how i can write this fields in a for cicle

I try differente way but without any result.

    //twig file
   {% for i in 0..10%}
             <tr>
                error <td>{{ form_widget(form.matricola_{{i}}) }}</td>
                error  <td>{{ form_widget(form.tipologia_{%i%}) }}</td>
                error  <td>{{ form_widget(form.esame_.i) }}</td>
            </tr>   
   {% endfor %}

Please help me and sorry for my english

尝试

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM