Handlebars Sum multiple products

Comments

1 comment

  • Tom Santiago Principal Technical Writer Community moderator
    Engaged
    Top Contributor
    Celigo University Level 4: Legendary

    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.