crmpicco crmpicco - 1 year ago 190
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


{% set currentType = site.getCurrentType() %}
{{ '{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 Source

DOZ hint was actually almost correct.


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

This works in my Code:

{{ (''~currentType)|trans({ '%url%' : path('appbundle_course_url', { 'subdomain': site.subdomain }) }) }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download