2011-04-22 96 views
5

如何使用Liquid中的地圖過濾器?我在Jekyll中使用它。液體模板地圖過濾器

--- 
my_array: [apple, banana, orage] 
my_map: 
    hello: world 
    foo: bar 
my_string: "how does this work?" 
--- 
{{ page.my_map | map ... }} 

這就是我在哪裏迷路。我似乎無法在文檔或任何其他網上找到任何關於此用法的示例。順便說一下,我不知道Ruby,但是,source code對我來說也不是很清楚。

從它看起來像下面應該生產的東西的filter tests,但在GitHub上,我得到什麼:

{{ site.posts | map: 'title' | array_to_sentence_string }} 

我希望,我應該得到的東西,如:

My First Blog Post, Yet Another Post, and Third Posts 

回答

8

我能夠做到你想要的這樣:

{{ site.posts | map: 'to_liquid' | map: 'title' | array_to_sentence_string }} 

說明:

我認爲site.posts返回Post實例的數組而不是返回他們的to_liquid版本(這感覺很奇怪 - 可能是一個錯誤,你應該報告它)。該類的實例不是respond_to? :title,並且由於Liquid代碼檢查該實例,所以map對於所有實例都返回nil。