简体   繁体   English

在细枝中的显示字符串中插入变量

[英]Insert a variable into a display string in twig

I saved my translation data in a database, each line contains a language in the twig template ,i set the variable so 我将翻译数据保存在数据库中,每一行在树枝模板中都包含一种语言,我将变量设置为

{% if app.request.getLocale()== 'en' %}
    {% set language = 1 %} 
{%else%}
    {% set language = 0 %} 
{% endif %}

i use this for display data from database 我用它来显示数据库中的数据

<p>{{indexpage.0.titpage}}</p>

I wanted to use the variable language to change the display 我想使用可变语言来更改显示

<p>{{indexpage.language.titpage}}</p>

I have tried it with concatenation and other ways but does not 我已经用串联和其他方式尝试过,但是没有

<p>{{indexpage.~language~.titpage}}</p>

How i can fix this ,thank very much 我该如何解决,非常感谢

假设它是一个数组,您可以执行以下操作:

<p>{{ indexpage[language].titpage }}</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM