[英]concat string and variable in twig
I have this in my template 我的模板中有这个
{{ ad.title_de }}
Now I'm incorporating multiple languages, so 'title_de' has to change I also have a variable 'tld' which is one of de, en , fr 现在,我合并了多种语言,因此必须更改“ title_de”,我还有一个变量“ tld”,它是de,en,fr中的一个
So I'd like to have something like 所以我想吃点东西
{% if tld == 'fr' %}
{{ ad.title_fr }}
etc Any ideas? 等有什么想法吗?
Try using the attribute
function. 尝试使用
attribute
功能。
http://twig.sensiolabs.org/doc/functions/attribute.html http://twig.sensiolabs.org/doc/functions/attribute.html
attribute(ad, 'content_'~tld)
should work. attribute(ad, 'content_'~tld)
应该起作用。
试试这个:
{{ ad["title_" ~ tld] }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.