Skip to main content

sum

Calculates the sum of all numeric values in an array. If a property is specified, it will sum the values of that property for each object in the array.

Basic Usage

Sums the numbers in an array.

{% set numbers = [1, 2, 3, 4, 5] %}
{{ numbers | sum }}

Output: 15

Summing a property

Sums the price property of each item in the cart.items array.

Total price: {{ cart.items | sum('price') }}