I have a type of content that i use on the homepage of a site I am building, the code is shown here:
<ul>
{% for point in entry.keyPoints %}
<li>
<div class="a-ico">
<i class="fa fa-{{ point.icon }}"></i>
</div>
<div class="a-info">
<h4>{{ point.heading }}</h4>
{{ point.text }}
</div>
</li>
{% endfor %}
</ul>
This does exactly what i want it to do. It opens a UL and then loops through the different items which are LI's and output accordingly.
I want to use this same type of content on inner pages however as a matrix block TYPE rather than being the only type of content like on the homepage in the above example.
The problem then is that the FOR loop starts before i even know if this is the type of content i am dealing with so I can't appropriately wrap this type in a UL.
I can solve this by checking if it is the FIRST of TYPE and LAST of TYPE and outputting the opening and closing UL tags that way.
I then run into another problem that the first and last of this type are not necessarily adjacent to each other. If that is the case then all the other content TYPEs in the matrix between the FIRST and LAST of this TYPE will be inside of the UL as well.
My question then is how can i determine if the other matrix blocks that are immediately adjacent to this TYPE are of the same TYPE and if they are don't close the UL and if they are NOT then close the UL.
My code to determine what type is is just a simple FOR loop and then inside it a series of conditionals checking the TYPE and then outputting the appropriate content accordingly.
.nextand not.prev, so that gave me a good clue. In my case the design called for mixing 3 different block types, 2 of which could be full width or half width. This isn't really answer to the question so I don't want to add lots of code here, but it may be useful to someone else: gist. I basically used a counter to check if the loop was at the first or last typetowrap block. Thanks @SimonKuran ! – Sebastian Thomas Jan 12 '16 at 09:51