Jekyll “where”未在CSV数据中查找给定参数的条目
杰基尔2.4.0,Mac 10.12.5Jekyll “where”未在CSV数据中查找给定参数的条目,jekyll,liquid,Jekyll,Liquid,杰基尔2.4.0,Mac 10.12.5 {% for year_of_interest in (1997..2017) reversed %} <large_year>{{year_of_interest}}</large_year> {% for paper in site.data.publications | where,'site.data.publications.Year',year_of_interest %} <
{% for year_of_interest in (1997..2017) reversed %}
<large_year>{{year_of_interest}}</large_year>
{% for paper in site.data.publications | where,'site.data.publications.Year',year_of_interest %}
<div class="publication_card">
<a class="article_title" href="../../{{paper.Link}}" title="{{paper.Abstract}}">{{paper.Title}}</a>
</div>
<div class="paper_author_container">
<span class="paper_authors">{{paper.Author | upcase}}</span>
<br>
<span class="journal_info">{{paper.Year}}—{{paper.Journal | upcase}}</span>
<button class="btn" data-clipboard-text="{{paper.BibTex}}">
BIBTEX
</button>
</div>
{% endfor %}
{% endfor %}
背景:我被卡住了!我有一个CSV,其中每一行代表1997年至2016年论文的出版物元数据。有些年份有许多论文,但每年至少有一篇发表。我希望每年有一个标题,并将出版物张贴在下面。不幸的是,where过滤器在for循环中找不到给定年份的任何文章
当前功能:在每个标题下,它显示所有出版物的列表。
需要:它应该只显示论文所在的出版物。年份==感兴趣的年份
提前谢谢 这是where过滤器的唯一文档,因为它不是默认的液体过滤器 site.data.publication.Year是site.data.publications的对象。我相信您只需要指定年份。顺便说一下,这是区分大小写的 {site.data.publications中的论文百分比|其中,Year,Year_of u interest%}这里有三个问题: 你不能在循环中过滤 将无法按预期工作,因为它始终返回所有数据
{% assign filtered = site.data.publications | where,'site.data.publications.Year', year_of_interest %}
{% for paper in filtered %}
会有用的,但不是现在
其中筛选器在密钥上进行筛选
它不是{%site.data.publications}其中,'site.data.publications.Year',Year_of_interest%}
但是:{%site.data.publications | where,'Year',Year_of u interest%}
快开始工作了
CSV数据是字符串
{site.data.publications[0].Year | inspect}}返回1987,双引号表示它是一个字符串,您的筛选器将永远找不到整数作为年份值。您必须查找字符串
要将整数转换为字符串,可以在其上附加一个空字符串
{% for year_of_interest in (1997..2017) reversed %}
{% comment %} casting an integer to a string {% endcomment %}
{% assign yearAsString = year_of_interest | append:"" %}
{% comment %} filtering datas {% endcomment %}
{% assign selectedEntries = site.data.publications | where: "Year", yearAsString %}
{% for paper in selectedEntries %}
现在,它完成了任务
注:
1-使用| inspect过滤器进行调试,它有助于确定值字符串、整数、数组和散列的类型
2-还可以通过向字符串中添加零将其强制转换为整数:
{% assign numberAsString = "1997" %}
{{ numberAsString | inspect }} => "1997"
{% assign numberAsInteger = numberAsString | plus: 0 %}
{{ numberAsInteger | inspect }} => 1997
没有运气;这种排列具有相同的结果。甚至当我把它改为:年,年的兴趣一样,要点是设置谢谢你的解释!如何启用检查?当我将其写入代码并运行bundle exec jekyll serve时,我没有看到任何输出?无需启用inspect,它是现成的。语法是{myVar | inspect}。
{% for year_of_interest in (1997..2017) reversed %}
{% comment %} casting an integer to a string {% endcomment %}
{% assign yearAsString = year_of_interest | append:"" %}
{% comment %} filtering datas {% endcomment %}
{% assign selectedEntries = site.data.publications | where: "Year", yearAsString %}
{% for paper in selectedEntries %}
{% assign numberAsString = "1997" %}
{{ numberAsString | inspect }} => "1997"
{% assign numberAsInteger = numberAsString | plus: 0 %}
{{ numberAsInteger | inspect }} => 1997