Symfony2-表单_小部件-复选框分开
我有这个:Symfony2-表单_小部件-复选框分开,symfony,twig,Symfony,Twig,我有这个: <fieldset> <legend>{{ form_label(form.fees, 'fees' | trans , { 'label_attr': {'class': 'col-sm-3 control-label'} }) }}</legend> <div class="large-12 columns fees"> <br/> {{ form_errors(form.
<fieldset>
<legend>{{ form_label(form.fees, 'fees' | trans , { 'label_attr': {'class': 'col-sm-3 control-label'} }) }}</legend>
<div class="large-12 columns fees">
<br/>
{{ form_errors(form.fees) }}
<div class="col-sm-5">
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
</div>
</div>
</fieldset>
但我需要这样的东西(带包装):
Tnx!!:) 如果您希望有四行复选框,则类似于:
{# Wrap span around checkboxes #}
{{ form_label(form.fees) }}
{{ form_errors(form.fees) }}<br>
{% for batch in form.fees|batch(4) %}
<div class="batchRow">
{% for option in batch %}
<div class="yourClassName">
{{ form_label(option) }}
{{ form_widget(option) }}
</div>
{% endfor %}
</div>
{% endfor %}
{#在复选框周围环绕span}
{{表格标签(表格费用)}
{{表格错误(表格费用)}}
{表格中批次费用的百分比|批次(4)%}
{批处理%中选项的%s}
{{form_标签(选项)}}
{{form_小部件(选项)}
{%endfor%}
{%endfor%}
否则,您可以取消批处理级别。您可以使用自定义单个字段。例如,您有
ProductType
表单,您的案例是费用。因此,您可以在顶层代码中添加这一行:
{# tell symfony use form theme #}
{% form_theme form _self %}
{# the block customize #}
{% block _product_fees_widget %}
<div>
{{ block('form_widget_simple') }}
</div>
{% endblock %}
{# print #}
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
{#告诉symfony使用表单主题}
{%form\u主题form\u self%}
{#块自定义}
{%block{u产品\费用\小部件%}
{{block('form_widget_simple')}
{%endblock%}
{打印}
{{form_小部件(form.fees,{'attr':{'class':'form control validate[required]}}}}
有关更多信息,请阅读此听起来像是您正在寻找的。如果您只想定制一个特定的表单(而不是所有表单),链接第一章链接指向一个合适的方法。要修改所有表单,请向下滚动一点。
{# Wrap span around checkboxes #}
{{ form_label(form.fees) }}
{{ form_errors(form.fees) }}<br>
{% for batch in form.fees|batch(4) %}
<div class="batchRow">
{% for option in batch %}
<div class="yourClassName">
{{ form_label(option) }}
{{ form_widget(option) }}
</div>
{% endfor %}
</div>
{% endfor %}
{# tell symfony use form theme #}
{% form_theme form _self %}
{# the block customize #}
{% block _product_fees_widget %}
<div>
{{ block('form_widget_simple') }}
</div>
{% endblock %}
{# print #}
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}