jekyll 变量,if 函数

jekyll variables, if functions

为什么这样的东西不起作用? 我尝试过滤今年的所有帖子

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

问题是它捕获的输出中有一些空格,所以它无法通过 if 条件,删除这些空格,它应该可以工作

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

获取 pubyear 是有效的,但您也可以分配没有空格的 pubyear。

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