【发布时间】:2018-01-21 07:24:17
【问题描述】:
我有一个github页面,其_include目录有一个文件courses.html:
{% assign id = include.lessonID | split: '.' %}
{% assign courseID = id | first %}
{% assign node = site.data.courses | where: "id","1" %}
{% assign node = node[1] %}
{%- if node.id == empty -%}
<h1> EMPTY NODE Warning</h1>
{%- else -%}
<h2> DATA Found! </h2>
ID: {{ node.id }}
{%- endif -%}
<p>CourseID: {{node.id}}</p>
<p>Name: {{ node.name }}</p>
<p>Link: {{ node.permalink }}</p>
{%- for node in site.data.courses -%}
{%- if node.id == 1 -%}
<p>{{ node.name }}</p>
<p>{{ node.permalink }}</p>
{%- endif -%}
{%- endfor -%}
_layout 中的一个名为 courses.html 的文件正在使用它:
{% include courses.html post=page.lessonInfo.lessonID post=page %}
最后,文件lister.md 包含以下内容:
---
layout: courses
title: 'Test'
lessonInfo:
lessonID : 1.1
modName: 'Installing RHEL Server'
chapterName: 'Using Essential Tools'
---
# There should be some course list around here!
输出如下:
找到数据!
编号:
课程编号:
名称:
链接:
RHCSA
/rhcsa
所以,node 变量显然不是空的,但是当我使用 where 子句选择数组的正确元素时,我无法访问任何属性。
但是,当在 for 循环中使用 if 语句的第二部分时,这有效。如何修复 where 子句?!
编辑
@JJJ 的建议确实解决了我的问题,但我现在有一个相关的问题。我不能用变量替换表达式where: "id","1" 中的常量1!我尝试了不起作用的正常 where 子句(带引号和不带引号)。所以,我尝试了一个 where 表达式,它也不起作用:
{% assign node = site.data.courses | where: "id",courseID %}
没用!
{% assign node = site.data.courses | where_exp: "selNode","selNode.id == courseID" %}
这个也不行。
我做错了什么,我该如何解决?
【问题讨论】:
-
请在不同的问题中发布不同的问题。
标签: jekyll liquid github-pages