Jekyll "Liquid syntax error" 有限制

Jekyll "Liquid syntax error" with limit

我不知道这里出了什么问题,我还有其他几段具有相同结构的代码,但它们没有 return 这个错误。

这是 HTML 文件 (item.html) 中我遇到问题的液体代码:

{% assign item-collection = site.item-collection | sort: 'date' | reverse %}
{% for item in item-collection %}
  {% if item.featured == true limit: 3 %}
    <div class="item">
    </div>
  {% endif %}
{% endfor %}

这是一个正在处理的 'item' (item.md);

---
layout: item
date: 2017-06-08 00:00:00
title: item 1
featured: true
tags:
---

这是终端 return 编辑的错误:

Regenerating: 1 file(s) changed at 2017-06-28 22:41:16     Liquid Warning: Liquid syntax error (line 30): Expected end_of_string but found id in "item.featured == true limit: 3" in /_layouts/item.html ...done in 1.337976 seconds.

如果我将日期留空,则不会发生此错误,但一旦输入内容,此错误就会停止构建网站。

如果我从 liquid 代码中删除 'limit: 3',错误也会消失,但我需要这个限制。

对我做错了什么有什么想法吗? 提前致谢!

limit 是一个 for 标签参数。它在特定索引处退出 for 循环。

if 标签之后使用它没有任何意义,并且在处理它时会混淆 Jekyll。

limit 标签移动到 for 循环行,它应该只迭代前三个项目。

{% for item in item-collection limit: 3 %}
 {% if item.featured  %}

根据评论更新

  • 按特色标签筛选项目

    {% assign item-collection = site.item-collection | where_exp:"item","item.featured == true" %}
    
  • 按日期排序结果

    {% assign item-collection = item-collection | sort: 'date' | reverse %}
    
  • 仅限 3 个特色列表 post

    <ul>
    {% for item in item-collection limit:3 %}
    <li>{{item.date}} - {{item.title}}</li>
    {% endfor %}
    </ul>
    

总结:

{% assign item-collection = site.item-collection | where_exp:"item","item.featured == true" %}

{% assign item-collection = item-collection | sort: 'date' | reverse %}

<ul>
{% for item in item-collection limit:3 %}
<li>{{item.date}} - {{item.title}}</li>
{% endfor %}
</ul>