我在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个可能性中没有一个能够抓住空帖。关于如何处理这些帖子的任何想法?
答案 0 :(得分:9)
确保您在事前没有任何内容
---
---
NO NEW LINE HERE !!
没有空间,没有新行
有时文本编辑器会在文件末尾添加换行符。 你可以用以下方法摆脱它:
{% assign content = post.content | strip_newlines %}
然后测试:
{% if content == "" %}