Symfony Form Theming:覆盖国家/地区选择选项模板

时间:2015-05-12 16:47:41

标签: php forms symfony internationalization theming

我有一个表单可以让国家选择如下:

<div class="form-group">
    <label for="form[country]" class="its--col-sm-2 control-label">{{ form_label(form.country) }}</label>
    <div class="its--col-sm-10">
        {{ form_widget(form.country, { 'attr':{'id': 'countryForm', 'class': 'form-control'} }) }}
    </div>
</div>

问题出现在AOTranslationBundle

这是一个很棒的捆绑。在db中注册所有在视图中呈现的翻译,并在工具栏中显示它们以进行翻译。

然后,symfony country choice尝试翻译Symfony\Component\Intl\Intl::getRegionBundle()->getCountryNames()返回的所有国家/地区。

我解决了这个重写 choice_widget_options

{% form_theme form _self %}

{%- block choice_widget_options -%}
    {% for group_label, choice in options %}
        <option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label }}</option>
    {% endfor %}
{%- endblock choice_widget_options -%}

我的问题是......我如何才能覆盖国家/地区选择选项而不是其他选择选项?

1 个答案:

答案 0 :(得分:0)

您只需覆盖该特定字段。

您可以尝试这种方法。 Customize individual field