Skip to main content

sum

Function sum 

Source
pub fn sum(
    state: &State<'_, '_>,
    values: Value,
    attribute: Option<&str>,
    start: Option<Value>,
    kwargs: Kwargs,
) -> Result<Value, Error>
Expand description

Sums up all the values in a sequence.

The filter accepts two arguments, positionally or by keyword:

  • attribute: can be set to an attribute or dotted path to sum up that attribute of the items. Items without it are skipped.
  • start: the value to start from (defaults to 0). Like in Jinja2 this can also be a list to concatenate lists.
{{ range(10)|sum }} -> 45
{{ range(10)|sum(start=10) }} -> 55
{{ items|sum(attribute="price") }}