2

Currently working on a tool built on Symfony. I am iterating over an array of configuration settings. The thing I want to achieve seemed simple enough:

I am trying to obtain a certain value. One of the keys has to be dynamic though. Below is a working example without the key being dynamic.

{% set id = tmod_config.content_1.id %}

("content_1" being the key in question)

The number at the end of the key has to be dynamic. I have tried a couple of things but wasn't able to achieve this. Up to this point I have access to the dynamic value, it just needs to be turned into a functioning key.

Any suggestions?

Question solved! Check the answers

3
  • What's the source for the dynamic part of the key? Commented Dec 5, 2016 at 13:35
  • @Yoshi It's a parameter that was passed with the rendering of the template. Anyway, I have managed to solve the problem just now. Thanks for thinking along! Commented Dec 5, 2016 at 13:40
  • Np ;) But leave an answer for future visitors. Commented Dec 5, 2016 at 13:41

2 Answers 2

5

As it is an array you could use either..

{% set id = tmod_config[content_1].id %}

or

{% set id = attribute(tmod_config, content_1).id %}
Sign up to request clarification or add additional context in comments.

1 Comment

Soon after posting the question I tried a solution similar to your first solution. Got it working now. Thank you!
1

Solved the problem soon after posting it!

It can easily be done like this:

{% set id = tmod_config["content_" ~ contentId].id %}

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.