液体标记地图过滤器示例 [英] Liquid Markup Map Filter Example
问题描述
我可以有怎样的液体过滤器的地图作品的一个普通例子吗?似乎没有成为这个文档。该图滤镜是图/收集特定属性的阵列? - 但你如何确定物业
这个例子的存在 - 液体模板图滤镜 - 但似乎具体到一个单次使用案件。如何地图工作一般?
据我了解,要过滤输出数组,但什么是地图中的参数?
例如:
{{page.tags |图:'名'}}
什么名字?是它的值被输出的标签?对于一个给定的对象,一个人如何确定哪些该标签可能是什么?
地图作品通过元素的数组的每个元素迭代,然后获取值指定属性。
您必须知道的属性是什么,你正在传递中元素的数组。
也就是说:如果你有一个collection.products,并且要抢集合中的每个产品的手柄,然后在一个逗号分隔字符串返回它们,那么你可以做:
{{collection.products |图:'处理'|加盟:','}}
这将列出所有产品的处理:
<$p$p><$c$c>across-the-mountains,alpine-meadow,appproaching-storm,arboretum-poster,around-st-peters,basic-tee,bryce-canyon-sunrise,crocuses,flower-print-mum,gatineau-park-stream,product-2,hooded-sweater,product-3,last-light-at-sandbanks,last-light-on-opabin-plateau,library-of-parliament,library-of-parliament-poster,long-beach-tofino,magnolia,meadow-2,mountain-panoramic-2,ready-to-frame-tulip-print-10,ready-to-frame-tulip-print-11,ready-to-frame-tulip-print-12,ready-to-frame-tulip-print-13,ready-to-frame-tulip-print-14,ready-to-frame-tulip-print-15,ready-to-frame-tulip-print-2,ready-to-frame-tulip-print-3,ready-to-frame-tulip-print-4,ready-to-frame-tulip-print-6,ready-to-frame-tulip-print-7,ready-to-frame-tulip-print-8,ready-to-frame-tulip-print-9,ready-to-frame-tulip-print-5,ready-to-frame-tulip-print-1,sample,shopify-shirt,shirt,sunset-on-lake-ohara,t-shirt,library-of-parliament2,test-prdouct,test-prod,test-product-1,test-product,testing,the-arboretum-poster,the-arboretum-central-experimental-farm,the-colosseumMay I have a generic example of how the Liquid map filter works? There doesn't appear to be documentation for this. The map filter is to "map/collect an array on a given property" - but how do you determine the property?
This example exists - Liquid Template Map Filter - but it seems specific to a single use case. How does map work generally?
I understand that the output to be filtered is array, but what is the parameter for map?
For example:
{{ page.tags | map: 'name' }}
What is name? Is it the label for the value to be output? For a given object, how does one determine what that label might be?
map works by iterating through each element of the array of elements, and then getting the value for the given property.
You would have to know what the property is for the array of elements you're passing in.
ie: if you had a collection.products, and you want to grab the handle for each product in the collection, and then return them in a comma seperated string, you could then do:
{{ collection.products | map: 'handle' | join: ',' }}
and that would list out all the product handles:
across-the-mountains,alpine-meadow,appproaching-storm,arboretum-poster,around-st-peters,basic-tee,bryce-canyon-sunrise,crocuses,flower-print-mum,gatineau-park-stream,product-2,hooded-sweater,product-3,last-light-at-sandbanks,last-light-on-opabin-plateau,library-of-parliament,library-of-parliament-poster,long-beach-tofino,magnolia,meadow-2,mountain-panoramic-2,ready-to-frame-tulip-print-10,ready-to-frame-tulip-print-11,ready-to-frame-tulip-print-12,ready-to-frame-tulip-print-13,ready-to-frame-tulip-print-14,ready-to-frame-tulip-print-15,ready-to-frame-tulip-print-2,ready-to-frame-tulip-print-3,ready-to-frame-tulip-print-4,ready-to-frame-tulip-print-6,ready-to-frame-tulip-print-7,ready-to-frame-tulip-print-8,ready-to-frame-tulip-print-9,ready-to-frame-tulip-print-5,ready-to-frame-tulip-print-1,sample,shopify-shirt,shirt,sunset-on-lake-ohara,t-shirt,library-of-parliament2,test-prdouct,test-prod,test-product-1,test-product,testing,the-arboretum-poster,the-arboretum-central-experimental-farm,the-colosseum
这篇关于液体标记地图过滤器示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!