jekyll variables, if functions

我与影子孤独终老i 提交于 2019-12-13 14:16:37

问题


Why is something like this not working ? i try to filter all posts from this year

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

回答1:


The problem is that it is capturing the output with some spaces in it, so it fails the if condition, remove those spaces and it should work

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



回答2:


Capturing the pubyear is vaild but you can also assign pubyear with no spaces.

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



来源:https://stackoverflow.com/questions/44265571/jekyll-variables-if-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!