Liquid Template Map Filter
How, exactly does one use the map filter in Liquid? I'm using it in Jekyll.
---
my_array: [apple, banana, orage]
my_map:
hello: world
foo: bar
my_string: "how does this work?"
---
{{ page.my_map | map ... }}
That's about where I get lost. I cannot see开发者_如何学编程m to find any example of its usage in the docs or anywhere else online for that matter.
By the way, I do not know Ruby, yet, so the source code is not clear to me, either.
From the filter tests it looks like the following should produce something, but on GitHub, I am getting nothing:
{{ site.posts | map: 'title' | array_to_sentence_string }}
I would expect that I should get something like:
My First Blog Post, Yet Another Post, and Third Posts
I was able to do what you want this way:
{{ site.posts | map: 'to_liquid' | map: 'title' | array_to_sentence_string }}
Explanation:
I think that site.posts
is returning an array of Post instances instead of returning their to_liquid
version (which feels very weird - probably it is a bug, you should report it). Instances of that class don't respond_to? :title
, and since the Liquid code checks for that, the map
returns nil for all instances.
精彩评论