The @key
below always gives 0 1 2 3
even in the second row. Please help.
Handlebars template:
{{#grouped_each 4 orderData}}
<div class="row">
{{#each this }}
<div class="col-md-3">
<div class="thumbnail">
<img src="{{getImageSourceChannel ../../channelNames @key name}}" class="">
<div class="caption">
<p><b>{{getObjectAtIndex ../../channelNames @key}}</b></p>
<p class="">{{slices.4.count}} new orders</p>
<p class="">{{slices.3.count}} back orders</p>
</div>
</div>
</div>
{{/each}}
</div>
{{/grouped_each}}
Handlebars partial:
Handlebars.registerHelper('grouped_each', function(every, context, options) {
var out = "", subcontext = [], i;
console.log(every);
console.log(context);
console.log(options);
if (context && context.length > 0) {
for (i = 0; i < context.length; i++) {
if (i > 0 && i % every === 0) {
out += options.fn(subcontext);
subcontext = [];
}
subcontext.push(context[i]);
}
out += options.fn(subcontext);
}
return out;
});