-
-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(filters): add array sum filter * docs(filters): array sum filter * docs: update versoin number in source/filters/sum.md --------- Co-authored-by: Jun Yang <harttleharttle@gmail.com>
- Loading branch information
1 parent
fe978c8
commit 629d958
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
title: sum | ||
--- | ||
|
||
{% since %}v10.10.0{% 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. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters