0

I have try many way but didn't work want to convert this php code in to twig code.

<?php echo $dynamic[$language[language_id]][header]; ?>

Please help me with that

2
  • 1
    Is that line correct? Unless language_id and header are defined constants. they will each trigger a "Use of undefined constant" warning. Commented Aug 14, 2018 at 10:53
  • yes in other version i am using same line but in twig i can't convert Commented Aug 14, 2018 at 10:59

2 Answers 2

2

You can just use the array notation inside twig as well

{{ dynamic[language['language_id']]['header'] }}

demo

As an alternative, u could use the attribute function. But this one is too complex for this situation imho

{{ attribute(attribute(dynamic, language['language_id']), 'header') }}
Sign up to request clarification or add additional context in comments.

Comments

0

It seems like what you are looking for is the attribute() function:

{{ attribute(dynamic, language['language_id']['header']) }}

2 Comments

If you only use attribute once, you might want to move the ) behind ['language_id']
In fact, I was misreading the question and it doesn't seem necessary to use the function at all. The first example from your answer seems to be the best solution.

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.