jekyll: check if there are no posts

拥有回忆 提交于 2019-12-10 15:38:14

问题


How can I check if there are no posts in the _posts folder?

So far, I've tried

{% if site.posts == null %}
  <p>No posts...yet.</p>
{% endif %}

and

{% if site.posts == nil %}
  <p>No posts...yet.</p>
{% endif %}

Is this possible in Liquid?


回答1:


Grab the size of the posts array and then compare that to 0:

{% assign psize = site.posts | size %}
{% if psize == 0 %} 
  <p>No posts...yet.</p>
{% endif %}


来源:https://stackoverflow.com/questions/46208588/jekyll-check-if-there-are-no-posts

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