Handlebars Sum multiple products
I have this little 1-2 liner right here. It multiplies price times amount for 3 different items. Is there any way to sum up all 3 values?
{{ times Form.Fields.Item#1price Form.Fields.Item#1amount times Form.Fields.Item#2price Form.Fields.Item#2amount times Form.Fields.Item#3price Form.Fields.Item#3amount }}
0
-
Hi Kevin Laugwitz,
It looks like you're using the wrong tags for your handlebars expression. You can multiply then sum the fields using the add and multiply handlebars helpers. I got something approximating what I think you're asking for using the following strategy:
{
"First Name": "{{name}}",
Total: {{add (multiply price1 amount1) (multiply price2 amount2) (multiply price3 amount3)}}
}The context record I used for this expression was:
{
"id": 123,
"name": "Bob",
"age": 33,
"price1": 10,
"price2": 20,
"price3": 30,
"amount1": 5,
"amount2": 2,
"amount3": 3
}The expression above yields the following result:
{
"First Name": "Bob",
Total: 180
}Let us know if that's still not working for you.
0
Please sign in to leave a comment.
Comments
1 comment