I need to open a row when the index modulus is 0 and close it when it is 1, something similar to this idea:
{{each posts}}
{{#if @index%2==0}}
<div class="row">
{{/if}}
<div class="col-lg-6">HELLO</div>
{{#if @index%2==1}}
</div>
{{/if}}
{{/each}}
OF course that this code/idea doesn't compile. How can I achieve it?
UPDATE Sorry, maybe I didn't explain it well. What I want to do is something similar to this PHP code but using meteor. (changed some numbers for a better understanding).
for($i = 0; $i<count(array); $i++):
if($i%4 == 0):
echo '<div class="row">';
endif;
echo '<div class="col-lg-3">HELLO</div>';
if($i%4==3 || $i == count(array) -1):
echo '</div>';
endif;
endfor;
I have one solution with a helper that returns a two dimensional array there is another way of doing it.
If you wish to create the element in the middle no matter what, I would do something like this
where (similar to @zim suggestion)
isEven
would be a template helper taking the index as its argument