为什么这样的东西不起作用? 我尝试过滤今年的所有帖子
<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>
关于jekyll 变量,if 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44265571/