Created
March 25, 2013 14:54
-
-
Save mkempe/5237663 to your computer and use it in GitHub Desktop.
Handlebars “forEach” helper. See http://stackoverflow.com/questions/11479094/conditional-on-last-item-in-array-using-handlebars-js-template for more information.
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 'forEach', (array, options) -> | |
return options.inverse @ if (options.inverse && !array.length) | |
array.map((item, index) -> | |
item.$index = index | |
item.$first = index is 0 | |
item.$last = index is array.length - 1 | |
options.fn item | |
).join '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment