duplic8
duplic8

Reputation: 129

jekyll: check if there are no posts

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?

Upvotes: 7

Views: 1710

Answers (2)

Convincible
Convincible

Reputation: 351

Here is a simpler approach.

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

Upvotes: 3

marcanuy
marcanuy

Reputation: 23982

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

Upvotes: 8

Related Questions