0

我在 Symfony 4.4 应用程序中覆盖表单中的标签时遇到问题:

{{ form_row(form.legal, {
   'label' : 'personal.form.fields.legal'|trans
}) }}

personal.form.fields.legal看起来像这样:

I agree that I am 18 and above, I have read and accept the <a href="/terms-cond">T&Cs</a>

我的表单定义:

 ->add('legal', CheckboxType::class,
   'required' => true,
   'mapped' => false,
])

我试图覆盖这个标签是这样的:

{% block _crmbundle_personal_legal_label %}
    <label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %} style="color: red;">
        {{ form_widget(form) }}
        {{ label|unescape|raw }}
    </label>
{%- endblock %}

我有一个 Twig 扩展可以做到这一点:

    public function getFilters(): array
    {
        return [
            new TwigFilter('unescape', function ($value) {
                return html_entity_decode($value);
            }),
        ];
    }

我发现这与标签重复,但我找不到纠正此问题的方法。我有一个复选框,但有两个标签(都显示为红色)

4

0 回答 0