So I have a matrix field with 3 different block types. The first two block types have markup contained within their scope. The last type, has opening and closing tags for the first of type and last of type (basically creating a row with two columns). I was able to successfully get the markup, but wanted to see if there is a better way to to this write this.
{% for block in entry.homeContentBlocks %}
{% if block.type == "leadGeneration" %}
...
{% elseif block.type == "banner" %}
...
{% else %}
{% if block.next() %}
{% if block.next().type == "contentBlock" %}<div class="row">{% endif %}
{% endif %}
{% if block.next() %}
{% if block.next().type == "contentBlock" %}
<div class="block-6 v-divider">
{% endif %}
{% endif %}
{% if block.prev() %}
{% if block.prev().type == "contentBlock" %}
<div class="block-6 pad-left">
{% endif %}
{% endif %}
<h3>{{ block.heading }}</h3>
{{ block.body }}
{% if block.btnLink | length %}
{% set link = block.btnLink.first().url %}
<a href="{{ link }}" class="btn">{{ block.btnLabel }}</a>
{% endif %}
</div>
{% if block.prev() %}
{% if block.prev().type == "contentBlock" %}</div>{% endif %}
{% endif %}
{% endif %}
{% endfor %}
So this works, but let's say the blocks out of sequence. I thought maybe a increment variable could work, but wasn't sure how to implement it.