Created
September 3, 2014 04:00
-
-
Save bencooling/5aee993c8b325ce130c9 to your computer and use it in GitHub Desktop.
zebra rows, stripes, odd & even classes handlebars 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("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(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment