Skip to content

Commit

Permalink
docs(filters): array sum filter
Browse files Browse the repository at this point in the history
  • Loading branch information
brunodccarvalho committed Dec 18, 2023
1 parent 76909a1 commit 2f12575
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/_data/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ filters:
strip: strip.html
strip_html: strip_html.html
strip_newlines: strip_newlines.html
sum: sum.html
times: times.html
truncate: truncate.html
truncatewords: truncatewords.html
Expand Down
22 changes: 22 additions & 0 deletions docs/source/filters/sum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: sum
---

{% since %}v?{% endsince %}

Computes the sum of all the numbers in an array.
An optional argument specifies which property of the array's items to sum up.

In this example, assume the object `cart.products` contains an array of all products in the cart of a website.
Assume each cart product has a `qty` property that gives the count of that product instance in the cart.
Using the `sum` filter we can calculate the total number of products in the cart.

Input
```liquid
The cart has {{ order.products | sum: "qty" }} products.
```

Output
```text
The cart has 7 products.
```

0 comments on commit 2f12575

Please sign in to comment.