Skip to content

Instantly share code, notes, and snippets.

@kylerush
Created January 11, 2013 15:52
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save kylerush/4511707 to your computer and use it in GitHub Desktop.
Save kylerush/4511707 to your computer and use it in GitHub Desktop.
An example of a blog post loop in Jekyll.
{% for post in site.posts %}
<article class="{% if forloop.first %}first{% elsif forloop.last %}last{% else %}middle{% endif %}">
<div class="article-head">
<h2 class="title"><a href="/{{ post.url }}/" class="js-pjax">{{ post.title }}</a></h2>
<p class="date">{{ post.date | date: "%b %d, %Y" }}</p>
</div><!--/.article-head-->
<div class="article-content">
{{ post.long_description }}
<a href="/{{ post.url }}/" class="full-post-link js-pjax">Read more</a>
</div><!--/.article-content-->
</article>
{% if forloop.last %}{% else %}<div class="separater"></div>{% endif %}
{% endfor %}
@wagnerrosa
Copy link

I was an hour trying the separator for loop.last.. You saved me! Thanks dude!

@fodra
Copy link

fodra commented Mar 11, 2017

alternatively, you could do

{% unless forloop.last %}<div class="separater"></div>{% endunless %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment