Answers.Body: <p>You can use a custom counter instead of using the <code>loop.index</code> value.</p>
  
  <pre><code>{% set step = 0 %}
  
  {% for block in entry.matrixBlocks %}
      {% if block.type == 'stepBlockType' %}
  
          {% set step = step + 1 %}
          Current step: {{ step }}
  
      {% elseif block.type == 'otherBlockType' %}
  
          {# Don't increase step count #}
  
      {% endif %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-26T16:50:57.127Z
Answers.LastActivityDate: 2016-07-27T05:43:28.183Z
Answers.LastEditDate: 2016-07-27T05:43:28.183Z
Answers.UserDisplayName: carlcs
Body: <p>I have a matrix set up with some blocks in it, and one of those blocks is to add "steps" to a page in a matrix. Now I'm trying to get the number of the step so that they only have to enter the content of the "steps" block, and that it automatically numbers it. </p>
  
  <p>For example:</p>
  
  <p>The matrix has 2 block types: "steps" and "image".
  If I make 2 "steps" blocks and 1 "image" block in this order: step - image - step, index.loop numbers the first step as one, and the 2nd step as three since image is in between them.</p>
  
  <p>Is it possible to have the "steps" numbered by position in the "steps" loop, and not in the full matrix?</p>
  
Tags: <templating><matrix><loop>
Title: Matrix: get the index number of a certain block
ThreadText: # Matrix: get the index number of a certain block
  
  (Asked by: username_0 on 2016-07-26)
  
  I have a matrix set up with some blocks in it, and one of those blocks is to add "steps" to a page in a matrix. Now I'm trying to get the number of the step so that they only have to enter the content of the "steps" block, and that it automatically numbers it.
  
  For example:
  
  The matrix has 2 block types: "steps" and "image".
  If I make 2 "steps" blocks and 1 "image" block in this order: step - image - step, index.loop numbers the first step as one, and the 2nd step as three since image is in between them.
  
  Is it possible to have the "steps" numbered by position in the "steps" loop, and not in the full matrix?
  
  **Tags:** templating, matrix, loop
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-07-26. Score: 7 | Accepted answer
  
  You can use a custom counter instead of using the `loop.index` value.
  
  ```
  {% set step = 0 %}
  
  {% for block in entry.matrixBlocks %}
      {% if block.type == 'stepBlockType' %}
  
          {% set step = step + 1 %}
          Current step: {{ step }}
  
      {% elseif block.type == 'otherBlockType' %}
  
          {# Don't increase step count #}
  
      {% endif %}
  {% endfor %}
  
  ```
  
  
  ---
  
  