2017-05-23 18 views
0

我有一個哲基爾收集其在不輸出,但在單頁上正在顯示它的元素,像這樣:有沒有辦法循環通過jekyll集合的前端問題?

{% for element in site.collection %} 
    {{ element.content }} 
{% endfor %} 

我希望能夠做這樣的事情:

{% for element in site.collection %} 
    {{ element.content }} 
    {% for front_matter in element %} 
    <!-- do stuff --> 
    {% endfor %} 
{% endfor %} 

這可以在YAML _data文件中使用YAML哈希值,但在此不起作用,因爲它似乎是{{ element }}本身與{{ element.content }}相同。似乎沒有爲此指定任何變量,如{{ element.front_matter }}。是否有可能通過jekyll集合中的元素的前端問題進行循環?

我知道,理想的方式,通過在一個變量做這將是包括所有我想環路front_matter,如:

--- 
front_matter: 
    foo: bar 
    bar: foo 
--- 

但是,正如我試圖配置這些配對( foobar)通過散文很容易更新,它們不能嵌套在其他值下。如果以散文的方式解決這個問題,我會接受這個答案。

非常感謝!

回答

1

它可以遍歷元素的變量在傑基爾集合:

{% for items in site.my_collection %} 
    {% for item in items %} 
    {{ item }}: {{ items[item] }} 
    {% endfor %} 
{% endfor %} 

但要記住,還有的是,也可以和將被包括在迭代其他元數據是很重要的,像pathurl等等,你的前面的問題,例如爲_my_collection/something.md

next: 

path: _my_collection/something.md 

output: <p></p> 

url: /my_collection/something.html 

id: /my_collection/something 

content: <p></p> 

collection: my_collection 

relative_path: _my_collection/something.md 

excerpt: <p></p> 

previous: 

draft: false 

categories: 

slug: something 

ext: .md 

tags: 

date: 2017-05-23 14:43:57 -0300 
+0

這很好,謝謝。我期待它返回鍵值對,但我想它只是返回鍵。 –

相關問題