Skip to content

Instantly share code, notes, and snippets.

@bencooling
Created September 3, 2014 04:00
Show Gist options
  • Select an option

  • Save bencooling/5aee993c8b325ce130c9 to your computer and use it in GitHub Desktop.

Select an option

Save bencooling/5aee993c8b325ce130c9 to your computer and use it in GitHub Desktop.
zebra rows, stripes, odd & even classes handlebars helper
Handlebars.registerHelper("stripes", function(array, even, odd, fn, elseFn) {
if (array && array.length > 0) {
var buffer = "";
for (var i = 0, j = array.length; i < j; i++) {
var item = array[i];
// we'll just put the appropriate stripe class name onto the item for now
item.stripeClass = (i % 2 == 0 ? even : odd);
// show the inside of the block
buffer += fn(item);
}
// return the finished buffer
return buffer;
}
else {
return elseFn();
}
});
{{#stripes myArray "even" "odd"}}
<div class="{{stripeClass}}">
... code for the row ...
</div>
{{else}}
<em>There aren't any people.</em>
{{/stripes}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment