My current code is like this which alternates between showing every 2 then every 1 item inside loop. I want it to show every 3 then every 1 item.
I use Adonis JS template engine (Edge)
<div class="column">
@each( PRO in products )
<div>{{ PRO.id }}</div>
@if($loop.index % 3 !== 0 && $loop.index + 1 !== products.length)
</div>
<div class="column">
@endif
@endeach
</div>
Its current result is like this:
<div class="column">
<div>1</div>
<div>2</div>
</div>
<div class="column">
<div>3</div>
</div>
<div class="column">
<div>4</div>
<div>5</div>
</div>
and I want it to become like this:
<div class="column">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div class="column">
<div>4</div>
</div>
<div class="column">
<div>5</div>
<div>6</div>
<div>7</div>
</div>
To get a
3-1-3-1...pattern, I would reason about something like:productsarray which would prevent creating an extra empty column<div>at the end as per my above logic.I have created a small snippet to test the above logic which you can refer to.