meteor - Handlebars and MeteorJs for every other or number -


i'm trying create handlebars.registerhelper() wrap {{>template}} in {{each items}} every number enter.

so this;

{{forevery items 4}}     {{> item_row_template}} {{/forevery}} 

the desired result every 4 items wrap around div.

<div class="row">     <div class="item_1">item</div>     <div class="item_2">item</div>     <div class="item_3">item</div>     <div class="item_4">item</div> </div>  <div class="row">     <div class="item_1">item</div>     <div class="item_2">item</div>     <div class="item_3">item</div>     <div class="item_4">item</div> </div> 

etc...

what want create helper iterate on list , manually append divs every often.

here example:

handlebars.registerhelper('forevery', function(context, limit, options) {     var ret = "";     if (context.length > 0) {         ret += "<div>";         for(var i=0, j=context.length; i<j; i++) {             ret = ret + options.fn(context[i]);             if ( (i+1) % limit === 0 ) {                 ret += "</div><div>";             }         }         ret += "</div>";     }     return ret; }); 

this function loop through array of items , every nth row close div , open new one. called like:

{{#forevery items 3}}     {{> item_row_template}} {{/forevery}} 

hope helps :)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -