Jekyll:检查帖子内容是否为空

时间:2014-12-05 22:47:14

标签: ruby jekyll liquid

我在Jekyll项目中有一系列帖子,其中一些只有一个标题,一些有标题和内容。我想在每种情况下用帖子做不同的事情。例如:

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

if语句实际上并没有抓住空帖。我的条件基于this page,但是3个可能性中没有一个能够抓住空帖。关于如何处理这些帖子的任何想法?

1 个答案:

答案 0 :(得分:9)

确保您在事前没有任何内容

---
---
NO NEW LINE HERE !!

没有空间,没有新行

有时文本编辑器会在文件末尾添加换行符。 你可以用以下方法摆脱它:

{% assign content = post.content | strip_newlines %}

然后测试:

{% if content == ""  %}