Want to add the each in to work in handlebars? This shows how it can be done. But note that it requires the stringParams flag at compile time, which changes the way all helpers get called, so this will probably break all the other helpers unless you provide stringParams compatible versions of them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Handlebars.registerHelper('each', function(localName,inKeyword,contextName,options){ var list = this[contextName]; var output = ""; var innerContext = Object.create(this); for (var i=0; i<list.length; i++) { innerContext[localName] = list[i]; output += options.fn(innerContext); } return output; }); var f = Handlebars.compile("{{#each number in numbers}}{{number}}{{/each}}", { stringParams: true }); console.log(f({numbers: [1,2,3]})); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.