简体   繁体   English

Symfony表单主题:覆盖国家/地区选择选项模板

[英]Symfony Form Theming: Override country choice option template

I have a form that renders a country select like this: 我有一个表格,可以像这样选择一个国家:

<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>

The problem comes with AOTranslationBundle . 问题来自于AOTranslationBundle

It's a great bundle. 这是一个伟大的捆绑。 Registers in db all translations that are being rendered in your view and show them in the toolbar for translation. 在db中注册在视图中呈现的所有翻译,并将其显示在工具栏中以进行翻译。

Then, symfony's country choice tries to translate all countries that Symfony\\Component\\Intl\\Intl::getRegionBundle()->getCountryNames() returns. 然后,symfony的国家/地区选择将尝试转换Symfony \\ Component \\ Intl \\ Intl :: getRegionBundle()-> getCountryNames()返回的所有国家。

I solved this overriding choice_widget_options 我解决了这个压倒性的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 -%}

My question is... How can i override just country select options and not other select options? 我的问题是...我如何才能仅覆盖国家/地区选择选项而不是其他选择选项?

You need to override for that particular field only. 您只需要覆盖该特定字段。

You can try this approach. 您可以尝试这种方法。 Customize individual field 定制个人领域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM