twig在symfony4中形成多个块

时间:2022-10-25 18:02:10

I have a form with block of the different input field.

我有一个带有不同输入字段块的表单。

When I use, standard twig function I get one block:

当我使用标准树枝功能时,我得到一个块:

{{ form(form) }}

If I want to change something inside form I use, for example:

如果我想改变我使用的形式内的东西,例如:

{{ form_start(form) }}
  {{ form_widget(form.firstName) }}
  {{ form_widget(form.lastName) }}
{{ form_end(form) }}

And everything is fine with this, but here I use JS for adding multiple block of the same field in the form (like can be possible to add multiple person in one form). When I want to edit data, I catch all data from the DB, of course, and want to show blocks in the twig.

一切都很好,但在这里我使用JS在表单中添加相同字段的多个块(就像可以在一个表单中添加多个人一样)。当我想编辑数据时,我会从数据库中捕获所有数据,当然,并希望在树枝中显示块。

{{ form_start(form) }}
  {# somehow start loop data from the DB here #}
    <div class='block'>
      {{ form_widget(form.firstName) }}
      {{ form_widget(form.lastName) }}
    </div>
  {# somehow end loop data from the DB here #}
{{ form_end(form) }}

Is it possible in the Twig, or I should use old school here?

是否有可能在Twig,或者我应该在这里使用旧学校?

1 个解决方案

#1


0  

For all who google for same question, answer is here: http://symfony.com/doc/current/form/form_collections.html

对于所有谷歌相同问题的人,答案在这里:http://symfony.com/doc/current/form/form_collections.html

#1


0  

For all who google for same question, answer is here: http://symfony.com/doc/current/form/form_collections.html

对于所有谷歌相同问题的人,答案在这里:http://symfony.com/doc/current/form/form_collections.html