Symfony 4-ChoiceType使用图标代替文本标签

在我的Symfony 4项目中,我有一个带有 CollectionType 的表单。 在子实体中,我有一个 ChoiceType 字段:

->add('type',ChoiceType::class,[
                "label" => "Type","choices" => [
                    "true" => "true","false" => "false"
                ],'label_attr'=>[
                    'class'=>'radio-inline'
                ],"expanded" => true,"multiple" => false,])

当前,我有此渲染图:

Symfony 4-ChoiceType使用图标代替文本标签

我希望能够显示“ true”和“ false”标签,而不是一个惊人的图标

我已经尝试了好几个小时,但徒劳地做不到。 我知道我必须使用表单主题,因此我尝试使用在很老的论坛帖子中找到的代码进行这种尝试

{% form_theme form.type
    'stripe/stripe_admin/subscription_plan/plan_details/_form_theme_plan_details_choice.html.twog'
%}

form_theme.html.twig

{% block choice_widget_options %}
{% spaceless %}
    {% for group_label,choice in choices %}
        <pre>
            {{ dump(choice) }}
        </pre>
        {% if choice is iterable %}
            <optgroup label="{{ group_label|trans({},translation_domain) }}">
                {% set options = choice %}
                {{ block('choice_widget_options') }}
            </optgroup>
        {% else %}
            <option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>
                  <img src="https://img.icons8.com/small/452/parse-from-clipboard.png" />
                  {{ choice.label|trans({},translation_domain) }}
            </option>
        {% endif %}
    {% endfor %}
{% endspaceless %}
{% endblock choice_widget_options %}

感谢您的帮助

nathansgl 回答:Symfony 4-ChoiceType使用图标代替文本标签

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2477255.html

大家都在问