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?

1 Answer 1


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 %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.