crmpicco crmpicco - 3 months ago 50
Twig Question

Using a Twig variable inside a Symfony translation in a template

It is getting late and I think my mind is shutting down...for the life of me I cannot work out how to change the translation key to work with the value of

currentType
.

{% set currentType = site.getCurrentType() %}
{{ 'messages.site.{currentType}'|trans({ '%url%' : path('appbundle_course_url', { 'subdomain': site.subdomain }) }) }}


I'm doing something derpy and will kick myself when I see the solution. I just know it.

Joe Joe
Answer

DOZ hint was actually almost correct.

'messages.site.'~currentType|trans

means translate currentType then append to string (Filter is applied first). So proper braces do the trick.

This works in my Code:

{{ ('messages.site.'~currentType)|trans({ '%url%' : path('appbundle_course_url', { 'subdomain': site.subdomain }) }) }}
Comments