Sefam
Sefam

Reputation: 1773

Using Twig variable inside Twig variable

I have a language JSON file containing the text of each page on my website. So to fetch the title of the page, I'll do something like

{{ translation.page1.title }}

In order to fetch the title for page 1.

I already have a page variable that tells me the name of the page, I was wondering if it was possible to do something to avoid having a giant if statement for each page such as:

{{ translation.{{ page }}.title }}

I've looked through the twig doc and I have no idea.

Upvotes: 0

Views: 69

Answers (1)

dhvarela
dhvarela

Reputation: 36

Try to put your variable between brackets

{{ translation[page].title }}

That should be work

Upvotes: 1

Related Questions