Php 自定义集合表单字段中的表单行
我正在尝试在表单布局中自定义特定的表单行。从中可以看出,如果我理解正确,我可以通过在表单主题文件中添加代码块来修改表单 我将字段添加到表单中,如下所示:Php 自定义集合表单字段中的表单行,php,forms,symfony,twig,Php,Forms,Symfony,Twig,我正在尝试在表单布局中自定义特定的表单行。从中可以看出,如果我理解正确,我可以通过在表单主题文件中添加代码块来修改表单 我将字段添加到表单中,如下所示: ->add('editions', 'collection', array('type' => new EditionType(), 'allow_add' => true, 'allow_delete' => true, 'by_reference' =&g
->add('editions', 'collection',
array('type' => new EditionType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
)
)
我以以下方式在模板中生成表单行,我需要数据原型标记,因为用户需要在查看表单时添加版本:
<div class="editions" data-prototype="{{ form_widget(form.editions.vars.prototype)|e }}">
{% for edition in form.editions %}
<section class="edition-container">
{{ form_label(edition.isbn) }}
{{ form_errors(edition.isbn) }}
{{ form_widget(edition.isbn) }}
</section>
{% endfor %}
</div>
{form.editions%}
{{form_label(edition.isbn)}
{{form_errors(edition.isbn)}
{{form_widget(edition.isbn)}
{%endfor%}
为了自定义“版本”字段的行,我尝试了以下方法:
<!-- Custom form theme for textarea label rows -->
{% block textarea_label %}
{% spaceless %}
<div {{ block('label_container_attributes') }}>
<label class="label">{{ label }}</label>
</div>
{% endspaceless %}
{% endblock %}
<!-- Custom form theme for edition field textarea label rows -->
{% block _booklist_editions_label %}
{% spaceless %}
<div {{ block('label_container_attributes') }}>
<label class="label">{{ label }}!</label>
</div>
{% endspaceless %}
{% endblock %}
{%block textarea_label%}
{%spaceless%}
{{label}}
{%endspaceless%}
{%endblock%}
{%block\u图书列表\u版本\u标签%}
{%spaceless%}
{{label}}!
{%endspaceless%}
{%endblock%}
不幸的是,第二个块不起作用,但第一个块起作用。我注意到的是,editions字段中的外部div没有包含字段名的id属性
这使我认为解决这个问题的办法可以是: