Search code examples
twigsymfony-3.3

Translation of a Label containing an url


In my symfony3 project, I have a form field with label "I accept the cgu" with a link on the 'cgu'. How can I translate the label containing the link, as I must generate the link with {{path('')}} in twig ?

I tried something like that : {{ 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 }) }} but it does not work...

Any idea ?

Thanks all !


Solution

  • When you are under {{ }}, you're writting an expression, so you can't put nested {{ }}.

    You can try with:

    {{ 
        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'})
            })
        }) 
    }}