2017-06-28 7 views
1

ここで何がうまくいかないのか分かりません。私は同じ構造のいくつかのコードを持っていますが、このエラーは返されません。ここで Jekyll "Liquid Syntax Error"(制限付き)

は私が悩みを抱えている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.md)が処理されているが、「アイテム」です。私はこのエラーが発生していない日の空のままにしておくと

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. 

、しかし、すぐに何かがこのエラーを入力するように構築されてからサイトを停止します。

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

はここで、端末によって返されるエラーです。

液体コードから 'limit:3'を削除するとエラーが消えますが、この制限が必要です。

私が間違っていることに関するアイデアはありますか? ありがとうございます!

答えて

2

limitは、forタグパラメータです。特定のインデックスでforループを終了します。

ifタグの後にそれを使用することは何の意味もなく、処理するときにジキルを混乱させます。

limitタグをループラインforに移動すると、最初の3つのアイテムだけが反復処理されます。コメントに基づいて、

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

更新機能を備えたタグによって

  • フィルタ項目

    {% assign item-collection = site.item-collection | where_exp:"item","item.featured == true" %} 
    
  • ソート機能を備えた3

    {% assign item-collection = item-collection | sort: 'date' | reverse %} 
    
  • 制限リストちょうど日付別結果役職

    <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> 
+0

おかげで理にかなって、私は、コレクション内の最初の3つの項目を巡回した後に終了するループのための必要はありません。私がしたいのは、コレクション内のすべてのアイテムを「フィーチャー」というタグでフィルター処理し、日付順に「フィーチャーされた」最大3つのアイテムを出力することです。これを行う方法はありますか? 「おすすめ」タグでコレクションをソートしようとしましたが、何もしないようです。 {%assign item-collection = site.item-collection |ソート:特集%} {アイテムコレクション%のアイテムの%} ありがとう – greystash

+0

更新された回答! – marcanuy

+0

ありがとうございました! – greystash