【发布时间】:2015-09-08 18:19:58
【问题描述】:
我有一个使用这个 courses.yml 的课程列表
- title: Basic Residential HSI Install
code: OSP0000111
description: Install and Repair residential and business class POTS, HSI, and Video services
newhire: true
skillset: Copper
jobtype: CST
advanced:
- title: PTA Testing Overview
code: OSP0000114
description: Teaches the technician how to close out a T1 test using the PTA system
newhire: false
skillset: Systems
jobtype: CO
advanced: no
- title: Technician Billing
code: OSP0000112
description: Teaches the technician how to properly bill the customer
newhire: false
skillset: Copper
jobtype: CST
advanced: yes
- title: Central Office Jumper
code: OSP0000113
description: Teaches the technician how to run jumpers
newhire: true
skillset: Copper
jobtype: CO
advanced: no
我列出的课程使用:
<ul>
{% for teds in site.data.courses %}
<li> Course Title: {{ teds.title }} <br />
Course Code: {{ teds.code}} <br />
Course Description: {{ teds.description }}
</li>
{% endfor %}
</ul>
这很好用。但是,现在我想使用相同的数据文件创建一个列表,仅列出那些 newhire 变量为“true”的课程。
我之前没有理解任何解释如何执行此操作的文档。我尝试了 where 子句和过滤器无济于事。
有什么想法吗?
根据https://jekyllrb.com/docs/templates/ 网站,我尝试添加 where 子句:
<ul>
{% for new in site.data.courses | where "newhire","true" %}
<li> Course Title: {{ new.title }} <br />
Course Code: {{ new.code }} | Job Type: {{ new.jobtype }} <br />
Description: {{ new.description }} <br />
<a href="{{ site.baseurl }}schedule.xlsx " target="_blank"> Schedule </a>
<hr />
</li>
{% endfor %}
</ul>
我刷新了页面,没有任何反应。我得到了相同的页面,所有课程的列表。没有过滤。我什至重新启动了 Jekyll 服务器。结果相同,没有过滤。
Jekyll 服务器也没有记录任何错误。
根据您的回答,我更改了数据文件变量。 2ea“0”,2ea“1”。然后我把html文件改成:
<ul>
{% assign teds = site.data.courses | where: 'newhire', 1 | sort: 'title' %}
{% for teds in courses %}
<li> Course Title: {{ teds.title }} <br />
Course Code: {{ teds.code }} <br />
Course Description: {{ teds.description }}
</li>
{% endfor %}
</ul>
Jekyll 服务器没有报告任何错误,但是当我刷新页面时,它根本没有显示任何数据。我希望没有 4 个标题的列表,也没有 2 个喜欢的列表,只是网页。 :(
UGGH,我在晚餐后查看时看到了我的错误:)
以下是有效的:
<ul>
{% assign new = site.data.courses | where: 'newhire', 1 | sort: 'title' %}
{% for teds in new %}
<li> Course Title: {{ teds.title }} <br />
Course Code: {{ teds.code }} <br />
Course Description: {{ teds.description }}
</li>
{% endfor %}
</ul>
【问题讨论】:
-
请添加失败尝试的代码,并描述他们产生的意外结果或错误。
-
m69,感谢您抽出宝贵时间研究此问题! -乔
标签: jekyll