我有一个没有输出的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
---
但是,由于我尝试将这些配对(foo
和bar
)配置为可以通过prose.io轻松更新,因此它们无法嵌套在其他值下。如果有的话
尽管如此,我会接受这个答案。
非常感谢!
答案 0 :(得分:2)
可以遍历Jekyll集合中元素的变量:
{% for items in site.my_collection %}
{% for item in items %}
{{ item }}: {{ items[item] }}
{% endfor %}
{% endfor %}
但重要的是要记住,还有其他元数据也可用,并将包含在迭代中,如path
,url
等,以及您的前端问题,例如: _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