Anyone knows how to concatenate strings in twig? I want to do something like:
{{ concat('http://', app.request.host) }}
#Using the ~ (Tilde) Operator The tilde character concatenates all operands (strings and/or variables) into a single string. For example: {{ foo ~ ' ' ~ bar ~ '!'
This should work fine:
{{ 'http://' ~ app.request.host }}
To add a filter - like 'trans' - in the same tag use
{{ ('http://' ~ app.request.host) | trans }}
As Adam Elsodaney points out, you can also use string interpolation, this does require double quoted strings:
{{ "http://#{app.request.host}" }}
Also a little known feature in Twig is string interpolation:
{{ "http://#{app.request.host}" }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With