michaelmcgurk michaelmcgurk - 4 months ago 32
Twig Question

Index value in for loop with Twig

I'd like to store the iteration value to use in

so it would be
and so on...

I tried using
but this didn't work.

{% for item in post.get_field('qanda') %}
<div class="panel panel-default">
<div class="panel-heading accordion-toggle question-toggle collapsed"
data-parent="#faqAccordion" data-target="#question{{item.id}}"
<h4 class="panel-title"><a class="ing">Q:
<div class="panel-collapse collapse" id="question{{item.id}}" style=
"height: 0px;">
<div class="panel-body">
</div>{% endfor %}


You can use the variable loop.index0 (for zero based indexing).


should do what you want. See the for loop documentation for more info for more information.