0

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.

1
  • 1
    {{ translation[page].title }} should work Commented Oct 12, 2016 at 21:55

1 Answer 1

1

Try to put your variable between brackets

{{ translation[page].title }}

That should be work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.