Hi Robin,
Thank you for helping me out 😊
I was trying to loop through exp:channel:entries and chunk the results similar to php array_chunk.
I was able to get around this by counting and then adding closing and open tags. In my case, I wanted to list 4 entries within a slide on a carousel. sample code:
<div id="fbReviewContent" class="carousel slide testimonials" data-ride="carousel">
<div class="carousel-inner" role="listbox">
{exp:channel:entries channel="social_reviews" orderby="title" sort="asc" }
{if count == '1'}
<div class="carousel-item text-center active">
<div class="container-fluid">
<div class="row mb-5">
{/if}
<div class="col-md-3 p-2">
<div class="testimonial text-center py-3 px-1">
<h4 class="stars">
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
</h4>
<h4>{title}</h4>
<div class="quote">
{page_content}
</div>
</div>
</div>
{if count % 4 == 0}
</div>
</div>
</div>
<div class="carousel-item text-center">
<div class="container-fluid">
<div class="row mb-5">
{/if}
{if absolute_count % 4 != 0 && total_results == absolute_count}
</div>
</div>
</div>
{/if}
{/exp:channel:entries}
</div>
</div>
Maybe there is another more cleaver/better ee-way of doing this?
Ah! Makes sense.
And honestly, what you did using the modulus operator is exactly how I would handle your example.
There’s always more than one way to approach things, but yours strikes me as a good first choice. Thanks for sharing it with the next person who wonders!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.