How to customize the data-prototype attribute in Symfony 2 forms

后端 未结 11 1035
梦如初夏
梦如初夏 2020-12-12 11:35

Since umpteens days, I block on a problem with Symfony 2 and forms.

I got a form of websites entities. \"Websites\" is a collection of website\'s entities and each w

11条回答
  •  有刺的猬
    2020-12-12 12:11

    A bit old, but here is a deadly simple solution.

    The idea is simply to render the collection items through a Twig template, so you have full ability to customize the prototype that will be placed in your data-prototype="..." tag. Just as if it was a normal, usual form.

    In yourMainForm.html.twig:

    And in MyBundle:MyViewsDirectory:prototype.html.twig:

    {{ form_label(form.field1) }} {{ form_widget(form.field1) }} {{ form_label(form.field2) }} {{ form_widget(form.field2) }}

    Credit: adapted from https://gist.github.com/tobalgists/4032213

提交回复
热议问题