Handlebar-helpers built-in blocks. Complex sum

51 Views Asked by At

Without creating a new helper and just use the existing one's from "handlebar-helpers" So I am actually trying to add the values in the below specified payload.

{
  "products": [
    {
      "product": [
        {
          "price": 10
        },
        {
          "price": 20
        },
        {
          "price": 30
        }
      ]
    },
    {
      "product": [
        {
          "price": 10
        },
        {
          "price": 20
        },
        {
          "price": 30
        }
      ]
    }
  ]
}

From the above payload. I am trying to compute the sum of products array based upon the index position of product array.

The output for this payload is 20 , 40 ,60 respectively.

I tried with pluck block as, {{pluck products "products.price"}} but it simply didn't work. Is there any workaround for this ?

Current logic that doesn't works.

{{#each products}}
    {{#each product}}
        {{sum (pluck products "product.price")}}
    {{/each}}
{{/each}}
0

There are 0 best solutions below