How can I wrap a div around certain neo fields based on what appears before or after them?
Basically I want to wrap a container div around a set of items (text based objects) only at the start and end of these objects but whenever they appear. Sometimes they might have one item other times they migjt have several.
I started with this but I am a little stuck
{% for block in entry.contentBuilder3.level(1) %}
{% set type = block.type.handle %}
{% set nextType = (not loop.last ? type) %}
{% set prevType = (not loop.last ? type) %}
{% if type in ['heading', 'body', 'downloads', 'textLinks' ] %}
{{ nextType }} :: {{ prevType }} this is a first child
<div class="max-w-2xl // min-w-75 // mx-auto // //// px-6 // border //">
{% endif %}
{% if prevType in ['heading', 'body', 'downloads', 'textLinks'] %}
</div>
{% endif %}
The above code currently wraps a div around each instance of the array not one around the group.
UPDATE:
After Marions helpful answer, I was unable to solve exactly with her method, but it did put me on the right tracks to solve it like so;
{% set inTheDiv = false %}
{% set nextType = null %}
{% set prevType = null %}
{% for block in entry.contentBuilder3.level(1) %}
{% set type = block.type.handle %}
{% set nextType = (not loop.last ? block.next.type.handle) %}
{% set prevType = (not loop.first ? block.prev.type.handle) %}
{% set fullWidth = block.fullWidth|default() %}
{% set textBlockArray = ['heading', 'body', 'downloads', 'textLinks', 'pullQuote', 'callToActionText'] %}
{% if type in textBlockArray and nextType in textBlockArray and prevType not in textBlockArray %}
<div class="mx-auto // max-w-2xl border border-red //// py-4">
{% endif %}
{% switch type %}
{# BLOCK TYPES CONTNET/TEXT #}
{% case 'heading' %}
{{ sectionSpacing }}
{% include '_includes/matrix3/heading' %}
{% case 'body' %}
{% include '_includes/matrix3/body' %}
{% case 'pullQuote' %}
{% include '_includes/matrix3/pullQuote' %}
{% case 'downloads' %}
{% include '_includes/matrix3/downloads' %}
{% case 'textLinks' %}
{% include '_includes/matrix3/textLinks' %}
{% case 'callToActionText' %}
{% include '_includes/matrix3/callToActionText' %}
{% case 'quote' %}
{% include '_includes/matrix3/quote' %}
{# LAYOUT BLOCKS #}
{% case 'tabbedContent' %}
<div class="-mx-6 //// {{ block.sectionSpacing }}">
{% include '_includes/matrix3/tabbedContent' %}
</div>
{% case 'tiles' %}
<div class="{% if fullWidth == true %}-mx-6{% else %}mx-auto // max-w-4xl flex{% endif %} //// {{ block.sectionSpacing }}">
{% include '_includes/matrix3/tiles' %}
</div>
{% case 'tileWithImage' %}
<div class="{% if fullWidth == true %}-mx-6{% else %}mx-auto // max-w-2xl{% endif %} //// {{ block.sectionSpacing }}">
{% include '_includes/matrix3/tileWithImage' %}
</div>
{% case 'textWithImage' %}
<div class="mx-auto // max-w-2xl //// {{ block.sectionSpacing }}">
{% include '_includes/matrix3/textWithImage' %}
</div>
{% case 'textWithVideo' %}
{% include '_includes/matrix3/textWithVideo' %}
{% case 'textWithText' %}
{% include '_includes/matrix3/textWithText' %}
{% case 'statistics' %}
{% include '_includes/matrix3/statistics' %}
{# MEDIA BLOCKS #}
{% case 'image' %}
{% include '_includes/matrix3/image' %}
{% case 'video' %}
{% include '_includes/matrix3/video' %}
{% case 'mediaGrid' %}
<div class="{{ block.sectionSpacing }}">
{% include '_includes/matrix3/mediaGrid' %}
</div>
{# CTA BLOCKS #}
{% case 'callToActionFull' %}
<div class="-mx-6 //// {{ block.sectionSpacing }}">
{% include '_includes/matrix3/callToActionFull' %}
</div>
{% case 'callOutBlock' %}
<div class="-mx-6 //// {{ block.sectionSpacing }}">
{% include '_includes/matrix3/callOutBlock' %}
</div>
{% endswitch %}
{% if type in textBlockArray and nextType not in textBlockArray and prevType in textBlockArray %}
</div>
{% endif %}
{% endfor %}
inTheDiv
, but never actually referring to it. – Marion Newlevant Jan 29 '18 at 20:40