我有一套代表我教的课程的集合。它们中的每一个都有一些与该课程相关的独特属性。例如:
# Collections, which are CS courses for me
collections:
cs1:
output: true
title: "CS1"
permalink: /teaching/cs1/:path/
TAemail: "cs1@school.edu"
cs2:
output: true
title: "CS2"
permalink: /teaching/cs2/:path/
TAemail: "cs2@school.edu"
...在每个集合中,有一个Logistics.md文件应该显示该课程的电子邮件地址。例如,如果课程是cs2,我想使用的是:
[Teaching team email](mailto:{{ site.cs2.TAemail }}) ...然而,这是行不通的。如果我将TAemail名称放在集合中的Logistics.md文件中,并对其执行某种查找,如:
{% for file in site.cs2 %}
{% if file.type == 'Info' %}
{% if file.subtype == 'Logistics' %}
| | email: | [ Team ](mailto: {{ file.TAemail }}) |
{% endif %}
{% endif %}
{% endfor %}效果很好。这看起来很尴尬,也不太像杰基尔。
有什么想法吗?
发布于 2016-06-17 02:29:46
{{ site.cs2.TAemail }}无法工作,因为site.cs2是一个包含集合项的数组,因此无法访问指定的元数据,因为它不是数组的属性。
访问集合元数据的方法是通过site.collections。
例如:
{% assign cs_collection = site.collections | where: "label", "cs1" | first %}
Send e-mail to: {{ cs_collection.TAemail }}顺便说一句,集合的每一项都包含一个名为collection的属性,该属性具有它所属的集合的名称,因此您可以基于该项动态查询集合,而不必在where过滤器中硬编码集合名称。
例如:
{% for item in site.cs1 %}
{% assign this_collection = item.collection %}
{% assign cs_collection = site.collections | where: "label", this_collection | first %}
Send e-mail to: {{ cs_collection.TAemail }}
{% endfor %}https://stackoverflow.com/questions/37868892
复制相似问题