1

Im trying to index a 2D list, whenever I access members.0, for example, the positioning works just fine. However I need this to change with the loop so I made a variable, but, if I was to do members.counter this wouldn't do anything.
Is there another way of doing this or is it not possible?

  <tbody>
      {% for item in projects %}
      {% with counter=forloop.counter0 %}
      <tr>
        <td>{{ item }}</td>
        <td>{{ members.counter }}</td>
      </tr>
      {% endwith %}
      {% endfor %}
  </tbody>

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Karna
  • 138
  • 7

1 Answers1

1

You can use the square brackets [] if you need to access a list or dict at a specific position:

<tbody>
  {% for item in projects %}
    {% with counter=forloop.counter0 %}
      <tr>
        <td>{{ item }}</td>
        <td>{{ members[counter] }}</td>
      </tr>
    {% endwith %}
  {% endfor %}
</tbody>
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83