Created
April 11, 2013 05:10
-
-
Save zeroasterisk/5360895 to your computer and use it in GitHub Desktop.
Example usage of Handlebars.registerHelper("foreach"... from http://stackoverflow.com/a/12002281/194105
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",function(arr,options) { | |
if(options.inverse && !arr.length) | |
return options.inverse(this); | |
return arr.map(function(item,index) { | |
item.$index = index; | |
item.$first = index === 0; | |
item.$last = index === arr.length-1; | |
return options.fn(item); | |
}).join(''); | |
}); |
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
<div class="carousel-inner"> | |
{{#foreach photos}} | |
<div class="item {{#if $first}} active {{/if}}"> | |
<div class="thumbnail"> | |
<a href="{{url}}" target="_blank"> | |
<img alt="{{title}}" src="{{url}}"> | |
</a> | |
</div> | |
</div> | |
{{/foreach}} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment