Adds map filter

This commit is contained in:
Adam Hollett
2016-03-15 19:36:24 -04:00
committed by Tetsuro
parent f5391d0621
commit 1aa4d93160
+19 -5
View File
@@ -2,10 +2,24 @@
title: map
---
Collects an array of properties from a hash.
Creates an array of values by extracting the values of a named property from another object.
| Code | Output |
|:-------------------------------------------------------|:-------------------|
| {% raw %}`{{ product | map: 'tag' }}`{% endraw %} | `["sale", "mens", "womens", "awesome"]` |
In this example, assume the object `site.pages` contains all the metadata for a website. Using `assign` with the `map` filter creates a variable that contains only the values of the `category` properties of everything in the `site.pages` object.
In the sample above, assume that `product` resolves to: `[{ tags: "sale"}, { tags: "mens"}, { tags: "womens"}, { tags: "awesome"}]`.
```liquid
{% raw %}
{% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %}
{{ item }}
{% endfor %}
{% endraw %}
```
```text
business
celebrities
lifestyle
sports
technology
```