Last active
December 20, 2017 11:28
-
-
Save uhtred/6439216 to your computer and use it in GitHub Desktop.
JS: Handlebars Simple Iteration Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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