-
-
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: introduce where_exp filter from Jekyll
- Loading branch information
Showing
7 changed files
with
109 additions
and
2 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
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,37 @@ | ||
--- | ||
title: where_exp | ||
--- | ||
|
||
{% since %}v10.12.0{% endsince %} | ||
|
||
Select all the objects in an array where the expression is true. In this example, assume you have a list of products and you want to show your kitchen products separately. Using `where_exp`, you can create an array containing only the products that have a `"type"` of `"kitchen"`. | ||
|
||
Input | ||
```liquid | ||
All products: | ||
{% for product in products %} | ||
- {{ product.title }} | ||
{% endfor %} | ||
{% assign kitchen_products = products | where_exp: "item", "item.type == 'kitchen'" %} | ||
Kitchen products: | ||
{% for product in kitchen_products %} | ||
- {{ product.title }} | ||
{% endfor %} | ||
``` | ||
|
||
Output | ||
```text | ||
All products: | ||
- Vacuum | ||
- Spatula | ||
- Television | ||
- Garlic press | ||
Kitchen products: | ||
- Spatula | ||
- Garlic press | ||
``` | ||
|
||
[truthy]: ../tutorials/truthy-and-falsy.html |
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,37 @@ | ||
--- | ||
title: where_exp | ||
--- | ||
|
||
{% since %}v10.12.0{% endsince %} | ||
|
||
从数组中选择所有表达式值为真的对象。下面的例子中,假设你要从产品列表中筛选出来厨房用品。利用 `where_exp` 可以创建一个只包含 `"type"` 为 `"kitchen"` 的列表。 | ||
|
||
输入 | ||
```liquid | ||
All products: | ||
{% for product in products %} | ||
- {{ product.title }} | ||
{% endfor %} | ||
{% assign kitchen_products = products | where_exp: "item", "item.type == 'kitchen'" %} | ||
Kitchen products: | ||
{% for product in kitchen_products %} | ||
- {{ product.title }} | ||
{% endfor %} | ||
``` | ||
|
||
输出 | ||
```text | ||
All products: | ||
- Vacuum | ||
- Spatula | ||
- Television | ||
- Garlic press | ||
Kitchen products: | ||
- Spatula | ||
- Garlic press | ||
``` | ||
|
||
[truthy]: ../tutorials/truthy-and-falsy.html |
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