Reputation: 466
I have a simple loop which requires me to concatenate my loop counter variable loop.index
within my main value variable (hope that makes sense) but I can't get it working.
Is it even possible? See below...
{% for article in section.articles %}
{{ article.internationalText~{{loop.index}} |raw|nl2br }}
{% endfor %}
Upvotes: 3
Views: 6509
Reputation: 103
You can use twigs attribute function which was added in version 1.2. It is designed for accessing a "dynamic" attribute of a variable.
{% for article in section.articles %}
{{ attribute(article, 'internationalText' ~ loop.index) |raw|nl2br }}
{% endfor %}
Note, benatespina's answer did not work for me.
Upvotes: 4
Reputation:
Have you tried this?
{% for article in section.articles %}
{{ article.internationalText~loop.index |raw|nl2br }}
{% endfor %}
This should work.
Upvotes: 2