使用 Jekyll ,我需要结合include / CSV Data的强大功能来生成表格 . 我试图在{}中使用"param"语句来传递一种变量来永不重复的帖子模板 .
-
内容基于_data / CSV文件;
-
每个帖子上的 Headers 和表格需要访问CSV中的一个参数(级别)才能获得正确的内容(CSV列显示1-2-3-4-5 ....)
-
在我传递的/ _include文件中:
<h1> {{ include.param }}</h1>
- 我在帖子中传递了param参数:
({% include xxx.ext param="1" %}
-
它在帖子上生成很好
<h1>1</h1>
-
我正在从CSV生成一个表,我需要它来理解嵌套for / if循环中的_post param = "1"(所以我可以从其他列中获取数据):
<tbody> {% for voc in site.data.vocs %} {% if voc.lecon == "{{ include.param }}" %} <tr> <td class="lecon"> {{ voc.lecon }} </td> <td> {{ voc.word }} </td> </tr>
当我生成网站时,Jekyll没有't understand the {} but only when it' s里面loop / if(这里: {% if voc.lecon == "{}" %} .
Jekyll如何理解在if语句中的帖子中传递的这个param(这是一个文章) .
谢谢 .
编辑:文件
CSV文件vocs.csv
`cumul,hsk,lecon,chinois,pinyin,francais
1,1,1,一,yī,A
2,1,2,不,bù,pas
3,1,4,买,mǎi,acheter
4,1,3,五,wǔ,cinq
[...]
`
帖子 - lecon-1.md
`
---
layout:
title: "Leçon 1"
categories:
- chinois-1
---
XXXXX
## Title
{% include vocabulaire.html param="1" %}
// The file below //
`
包含解释循环以填充帖子
`<h1> Vocabulaire {{ include.param }}</h1>
<table>
<thead>
<tr>
<th>Leçon</th>
<th>HSK</th>
<th>Chinois</th>
<th>Pinyin</th>
<th>Français</th>
<th>Audio</th>
<th>Plus</th>
</tr>
</thead>
<tbody>
{% for voc in site.data.vocs %}
{% if voc.lecon == {{ include.param }} %}
<tr>
<td class="lecon">
<a href="{{ lecon }}" target="_blank"> {{ voc.lecon }}</a>
</td>
<td class="hsk">
<a href="{{ hsk }}"> {{ voc.hsk }}</a>
</td>
<td lang="zh-Hans">
{{ voc.chinois}}
</td>
<td class="pinyin">
{{ voc.pinyin }}
</td>
<td class="alpha" lang="fr">
{{ voc.francais }}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
当前结果
源代码显示了一个巨大的空白
所以我希望帖子显示表格数据,但只有 if csv lecon = 1 . 我将保存此模板,以便当lecon = 2,lecon = 3等时我可以显示相同的模式...
1 回答
删除双引号和花括号可能会完成
{% if voc.lecon == include.param %}
的工作 .