首页 文章

如果类别中没有Jekyll帖子,如何创建IF ELSE语句?

提问于
浏览
21

我有一个FOR语句,输出 jobs 类型的所有帖子 .

{% for post in site.categories.jobs %}
  <article>
    <h3><a href="{{ post.permalink }}">{{ post.title }}</a></h3>
    <p>{{ post.summary }}</p>
  </article>
{% endfor %}

但如果 jobs 中没有已发布的帖子,我想显示"We're not hiring right now"消息 .

你能创建一个IF / ELSE语句来检查特定类别的帖子吗?

1 回答

  • 35

    尝试使用 {% if site.categories.jobs == null %} 进行检查 .

    {% if site.categories.jobs == null %}
      <p>We're not hiring right now</p>
    {% else %}
      {% for post in site.categories.jobs %}
        <article>
          <h3><a href="{{ post.permalink }}">{{ post.title }}</a></h3>
          <p>{{ post.summary }}</p>
        </article>
      {% endfor %}
    {% endif %}
    

相关问题