mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feat: Array sum filter (#661)
* 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 <[email protected]>
This commit is contained in:
co-authored by
Jun Yang
parent
fe978c8cd9
commit
629d958b86
@@ -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
|
||||
|
||||
@@ -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.
|
||||
```
|
||||
Reference in New Issue
Block a user