From 1aa4d931605d6c069106f471f07cd648fadc7add Mon Sep 17 00:00:00 2001 From: Adam Hollett Date: Fri, 29 Jan 2016 18:21:54 -0500 Subject: [PATCH] Adds map filter --- filters/map.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/filters/map.md b/filters/map.md index 769b976a..37b7b9aa 100644 --- a/filters/map.md +++ b/filters/map.md @@ -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 +```