1

I would like to set translated label for checkbox using twig. In documentation it is said that I can set label like this:

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

Unfortunatelly label is not changing at all. Am I missing something here?

1 Answers1

0

It may not work this way. I used to declare Twig variable for this purpose and that worked for me. According to your code, it will be something like this:

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

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

Check also this issue: How to translate labels in symfony2 forms with messages.en.yml? Here is a lot of similar solutions.

Varg
  • 402
  • 1
  • 6
  • 24
  • YOur solution didn't work, but the one from link below worked :) –  Jun 20 '17 at 08:05
  • @IgnasDamunskis, it worked nicely on my staging server. I'll debug it more carefully, but I am glad that my link helped you. – Varg Jun 21 '17 at 01:31