Skip to content

Instantly share code, notes, and snippets.

@zeroasterisk
Created April 11, 2013 05:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zeroasterisk/5360895 to your computer and use it in GitHub Desktop.
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
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('');
});
<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