0

I am creating a variable inside of a forloop. The variable is set to an code representing the value of a module. I need to inject another variable into this expression. concatenation turns the expression into a string. Below is the variables that should be created.

{% set texter = widget_data.text.value %}
{% set texter = widget_data.text_2.value %}
{% set texter = widget_data.text_3.value %}

my code:

 {% for item in range(3) %}
    {% if loop.index > 1 %}
        {% set unique = "_" + loop.index %}
    {% else %}
        {% set unique = "" %}
    {% endif %}

    {% set texter = "widget_data.text" ~ unique ~ ".value" %}
{% endfor %}

The variables are set to the right text, but it's a string so it ouputs the text instead of the value the text represents. I can't seam to find a way to turn this back into an expression.

JSum
  • 597
  • 9
  • 20

1 Answers1

0

Use filter attr to obtain the value of a calculated attribute of an object.

{% set texter = (widget_data | attr('text' ~ unique)).value %}
blhsing
  • 91,368
  • 6
  • 71
  • 106