Search code examples
javascriptexpresshandlebars.jsexpress-handlebars

How do I write this pug function in handlebars?


Can someone tell me how I can write the following pug code in handlebars code?

ul
      for product in products
          li #{product.product}
          li #{product.price}

I found the following code, but I have to populate two points per iteration. So I don't know how to implement that.

handlebars.registerHelper('list', function(n, block) {
    var accum = '';
    for(n in block)
        accum1 += block.fn(n);
    return accum;
});

Thanks.


Solution

  • Try this

    <ul>
    {{#each products}}
       <li>{{product}}</li>
       <li>{{price}}</li>
    {{/each}}
    </ul>