-
-
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.
- Loading branch information
1 parent
76909a1
commit 2f12575
Showing
2 changed files
with
23 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 %}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. | ||
``` |