2017-05-30 89 views
2

爲什麼這樣的事情不起作用? 我嘗試從今年過濾所有帖子jekyll變量,如果功能

<div class="tiles"> 
{% for post in site.categories.articles %} 

    {% capture pubyear %} {{ post.date | date: "%Y" }} {% endcapture %} 

    {% if pubyear == "2014" %} 
     {% include post-grid.html %} 
    {% endif %} 

{% endfor %} 
</div><!-- /.tiles --> 

回答

0

的問題是,它捕獲與它的一些空間的輸出,所以它失敗了,如果條件下,刪除這些空格,它應該工作

<div class="tiles"> 
    {% for post in site.categories.articles %} 
    {% capture pubyear %}{{ post.date | date: "%Y" }}{% endcapture %} 
    {% if pubyear == "2014" %} 
     {% include post-grid.html %} 
    {% endif %} 
    {% endfor %} 
</div> 
+0

是!!!!謝謝 – wwwSammy

+0

所以我比較 {%if pubyear ==「2014」%} – wwwSammy

+0

那麼我會刪除捕獲標記和post.date之間的空間,在我已經刪除它們的例子。 – marcanuy

0

抓取pubyear是vaild,但您也可以指定pubyear沒有空格。

{% assign pubyear = post.date | date: "%Y" %}