Reputation: 125
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
Upvotes: 2
Views: 1015
Reputation: 8276
Assuming it's an array you can do this:
<p>{{ indexpage[language].titpage }}</p>
Upvotes: 3