26

I have a FOR statement that outputs all posts of type jobs.

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

But if there are no published posts in jobs I would like to display a "We're not hiring right now" message.

Can you create an IF/ELSE statement to check for posts in a specific category?

astanush
  • 413
  • 1
  • 4
  • 9

1 Answers1

41

Try check it with {% 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 %}
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
  • 7
    Jekyll uses the [Liquid Template Language](https://github.com/Shopify/liquid/wiki/Liquid-for-Designers) for future reference, too. – Greg Burghardt May 29 '14 at 01:55