Symfony2 如何呈现复选框? [英] Symfony2 how to render Checkboxes?
问题描述
我有一个包含多个国家/地区选择列表的表单构建器表单.当我像这样在表单上呈现它们时:
I have a formbuilder form with a multiple choice list of countries. When I render them on my form like this:
{{ form_widget(edit_form.countries) }}
它们看起来像这样:
<input type="checkbox" name="..." value="AD" /><label for="...">Andorra</label>
<input type="checkbox" name="..." value="AE" /><label for="...">United Arab Emirates</label>
<input type="checkbox" name="..." value="AF" /><label for="...">Afghanistan</label>
我希望每个选项都显示在浏览器中的一行中,而不是全部显示在一行中.如何在选项周围或之间注入 html?或者是否有 CSS 方法可以实现此目的?
I would like each option displayed on it's own line in the browser, instead of all in a row. How can I inject html around or between the options? Or is there a CSS method to accomplish this?
谢谢.
推荐答案
来自 Symfony 文档
From The Symfony Docs
您基本上需要做的是重载 checkbox_widget 块.
What you basically need to do is to overload checkbox_widget block.
{% form_theme form _self %}
{% block checkbox_widget %}
{% spaceless %}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
{% endspaceless %}
{% endblock checkbox_widget %}
当然,您可以使用 CSS 将小部件放在自己的行中(但这不是 Symfony2 的问题).
Of course you can place your widgets in its own line with CSS (but it's not a Symfony2 question).
这篇关于Symfony2 如何呈现复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!