Skip to content

Instantly share code, notes, and snippets.

@codexico
Created January 19, 2013 19:53
Show Gist options
  • Save codexico/4574694 to your computer and use it in GitHub Desktop.
Save codexico/4574694 to your computer and use it in GitHub Desktop.
//http://tryhandlebarsjs.com/
//{{#list_fl people}}{{firstName}} {{lastName}}{{/list_fl}}
{
people : [
{ firstName: "Yehuda", lastName: "Katz" },
{ firstName: "Carl", lastName: "Lerche" },
{ firstName: "Alan", lastName: "Johnson" }
]
}
Handlebars.registerHelper('list_fl', function(items, fn) {
var out = "<ul>";
for(var i=0, l=items.length; i<l; i++) {
out += "<li";
if(i === 0){ out += ' class="first"';}
if(i+1 === l){ out += ' class="last"';}
out += ">";
out += fn(items[i])
out += "</li>";
}
return out + "</ul>";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment