Skip to content

Instantly share code, notes, and snippets.

@uhtred
Last active December 20, 2017 11:28
Show Gist options
  • Save uhtred/6439216 to your computer and use it in GitHub Desktop.
Save uhtred/6439216 to your computer and use it in GitHub Desktop.
JS: Handlebars Simple Iteration Helper
Handlebars.registerHelper( 'times', function( n, block ) {
var accum = '',
i = -1;
while( ++i < n ) {
accum += block.fn( i );
}
return accum;
});
How To:
{{#times 3}}
<span>{{this}}</span>
{{/times}}
Print:
<span>1</span>
<span>2</span>
<span>3</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment