I have a series of posts in a Jekyll project where some of have just a title and some have a title and content. I want to do different things with the post in each case. For example:
{% for post in site.categories.publications %}
{{ post.title }}
{% if post.content == "" or post.content == nil or post.content == blank %}
<p>Nothing here.</p>
{% else %}
{{ post.content }}
{% endif %}
{% endfor %}
But the if
statement doesn't actually catch the empty posts. I based my conditions on this page, but none of the 3 possibilities catch the empty posts. Any ideas on how to handle these posts?
Make sure that you have nothing after your front matter
---
---
NO NEW LINE HERE !!
No spaces, no new lines
Sometimes text editors will add a newline at the end of the file. You can get rid of that with:
{% assign content = post.content | strip_newlines %}
and then test with:
{% if content == "" %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With