I’m using meteor 1.8. I have a collection, and i should display only 5 elements per row,
i have code like this:
Template.tasks.helpershelpers({
tasks: function(counter){
return Tasks.find({}, {limit: Template.instance().max.get()});
});
So from helper limited number of tasks returned, then i display the button to load more.
html
{{#if Template.subscriptionsReady}}
<div class="tasks">
<div class="row">
{{#each tasks}}
<h5>{{this.data}}</h5> <!--and so on-->
{{/each}}
</div>
</div>
{{#if needsData}}
<button type="button" class="btn btn-primary" id="needs-data">Load More</button>
{{/if}}
{{else}}
{{>waitforme}}
{{/if}}
I have a question, how can i display only 5 elements in each loop, and then conditionally insert break? so each 5 elements would be wrapped into
<div class="tasks">
<div clas s="row">
<!--5 elements -->
</div>
<div clas s="row">
<!--5 elements -->
</div>
<!--etc-->
</div>
so pseudocode:
<div class="row">
for(i = 0; i < tasks.count(); i++)
{
if(i + 1 % 5 == 0){
</div>
<div class="row">
}
}
Something like this. I tried creating a helper to check for current index:
breakme: function(counter){
if(counter == 0){
return true;
}
else if(counter % 5 == 0)
return true;
return false;
}
and in my template:
<div class="tasks">
{{#each tasks}}
{{#if breakme @index}}
<div class="row">
{{/if}}
<h5>{{this.data}}</h5> <!--and so on-->
{{#if breakme @index}}
</div>
{{/if}}
{{/each}}
</div>