Tom Tom - 13 days ago 6
Twig Question

Use twig variable in string

For the language selection I want to show the flag of the current active languages.

I get the language variable by:

app.request.locale


Now I want to use the value in the string of the flag url.

<img src="{{ asset('flags/'+app.request.locale+'.png', 'img') }}" />


But what is the correct syntax for this?

Answer

You have to use ~ char instead of +.

Comments