sum
Sum returns the numeric sum of the elements of a slice.
Sum returns the numeric sum of the elements of a slice. With no parameter, every element must be (or be parseable as) a number. With a string field parameter, each element is treated as a map and the named field is summed.
Input
array
Parameters
| # | Type | Required |
|---|---|---|
| 0 | string | no |
Returns
float
Examples
Total a list of amounts
Input
amounts = [12.50, 8.00, 4.25]Template
{{ amounts | sum }}Output
24.75Total an order from line items
Input
items = [{"name": "Mug", "price": 12}, {"name": "Pen", "price": 3}, {"name": "Pad", "price": 5}]Template
{{ items | sum:'price' }}Output
20How is this guide?