Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an IF ELSE statement if there are no Jekyll posts in a category?

Tags:

jekyll

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?

like image 864
astanush Avatar asked May 28 '14 23:05

astanush


1 Answers

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 %} 
like image 164
Yi Zeng Avatar answered Oct 02 '22 17:10

Yi Zeng