jekyll: check if there are no posts
Asked Answered
I

2

7

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?

Isaak answered 14/9, 2017 at 0:11 Comment(0)
V
8

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 %}
Vosges answered 14/9, 2017 at 0:28 Comment(1)
This doesn't work either (i.e. this doesn't show the <p> element).Isaak
U
3

Here is a simpler approach.

{% if site.posts.size == 0 %}
  <p>No posts...yet.</p>
{% endif %}
Unlicensed answered 6/3, 2022 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.