Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jekyll: check if there are no posts

Tags:

jekyll

liquid

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?

like image 715
duplic8 Avatar asked Sep 14 '17 00:09

duplic8


1 Answers

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 %}
like image 71
marcanuy Avatar answered Sep 29 '22 16:09

marcanuy