2017-05-30 55 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" %}