formssymfonytwigtranslatetwig-filter

Html translation with parameters in symfony3 / twig


I have a pb with a translation containing parameters (link href). I have added a |raw but I see the html displayed.

My code :

{{ form_row(form.valid, {

'label' : 'annonces.form.valide_cgu_cgv' | trans ({

'cgu_link' : path('page_statique', {'page' : 'cgu'}),

'cgv_link' : path('page_statique', {'page' : 'cgv'})

}) | raw }) }}

What I see :

Je reconnais accepter les <a href="/page/cgu">Conditions générales d'utilisation</a> et <a href="/page/cgv">Conditions générales de vente</a>

Any idea ?

Thank you !


Solution

  • As the form_label use trans() without the raw inside of its code

    {%- block form_label -%}
        {# [...] #}
            <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
        {%- endif -%}
    {%- endblock form_label -%}
    

    You need either to use a custom form_label or 'manually' display the label