<p>Yes that's possible, all Twig loops have a <a href="http://twig.sensiolabs.org/doc/tags/for.html#the-loop-variable" rel="noreferrer"><code>loop</code> variable</a>:</p>

<blockquote>
  <p><code>loop.index</code> - The current iteration of the loop. (1 indexed)<br>
  <code>loop.index0</code> - The current iteration of the loop. (0 indexed)</p>
</blockquote>

<p><strong>Example:</strong></p>

<pre class="lang-twig prettyprint-override"><code>{% for block in entry.myMatrixField %}
  {% if block.type == "quote" %}
    &lt;blockquote class="quote{{ loop.index }}"&gt;
      &lt;p&gt;{{ block.quote }}&lt;/p&gt;
    &lt;/blockquote&gt;
  {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-08-13T11:39:41.070Z
2014-08-13T11:39:41.070Z
Victor
<p>Just wondering if there's a way to return the matrix block number during the loop?</p>

<p>For example:</p>

<pre><code>{% for block in entry.myMatrixField %}
  {% if block.type == "quote" %}
    &lt;blockquote class="quote{{GET_BLOCK_NUMBER}}"&gt;
      &lt;p&gt;{{ block.quote }}&lt;/p&gt;
    &lt;/blockquote&gt;
  {% endif %}
{% endfor %}
</code></pre>

<p>Might return something like this:</p>

<pre><code>&lt;blockquote class="quote1"&gt;
  &lt;p&gt;Curabitur aliquet quam id dui posuere blandit.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote class="quote2"&gt;
  &lt;p&gt;Curabitur aliquet quam id dui posuere blandit.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote class="quote3"&gt;
  &lt;p&gt;Curabitur aliquet quam id dui posuere blandit.&lt;/p&gt;
&lt;/blockquote&gt;
</code></pre>

<p>Thanks, Mark</p>

<matrix>
Return Matrix Field block number
# Return Matrix Field block number

(Asked by: username_0 on 2014-08-13)

Just wondering if there's a way to return the matrix block number during the loop?
For example:
{% for block in entry.myMatrixField %}
  {% if block.type == "quote" %}
    
      {{ block.quote }}
    
  {% endif %}
{% endfor %}

Might return something like this:

  Curabitur aliquet quam id dui posuere blandit.


  Curabitur aliquet quam id dui posuere blandit.


  Curabitur aliquet quam id dui posuere blandit.


Thanks, Mark

**Tags:** matrix


---

## 1 answers

### Answer by username_1 on 2014-08-13. Score: 8 | Accepted answer

Yes that's possible, all Twig loops have a loop variable:

loop.index - The current iteration of the loop. (1 indexed)
loop.index0 - The current iteration of the loop. (0 indexed)

Example:
{% for block in entry.myMatrixField %}
  {% if block.type == "quote" %}
    
      {{ block.quote }}
    
  {% endif %}
{% endfor %}


---

