无法从树枝设置复选框标签

Can not set checkbox label from twig

我想使用 twig 为复选框设置翻译标签。在 documentation 中,据说我可以这样设置标签:

{{ form_widget(search_form.matched, { 'id': 'matched' }) }}
{{ form_label(search_form.matched, 'only_matched'|trans({}, 'offers')) }}

不幸的是标签根本没有改变。我在这里遗漏了什么吗?

这样可能行不通。我曾经为此目的声明 Twig 变量,这对我有用。根据您的代码,它将是这样的:

{% set var = 'only_matched'|trans({}, 'offers') %}

{{ form_widget(search_form.matched, { 'id': 'matched' }) }}
{{ form_label(search_form.matched, var) }}

还要检查这个问题:How to translate labels in symfony2 forms with messages.en.yml? 这里有很多类似的解决方案。