Skip to content

Instantly share code, notes, and snippets.

@nternetinspired
Last active April 25, 2021 02:17
Show Gist options
  • Save nternetinspired/72e10633036f5f2a734953cc69e157c8 to your computer and use it in GitHub Desktop.
Save nternetinspired/72e10633036f5f2a734953cc69e157c8 to your computer and use it in GitHub Desktop.
Loop through Jekyll collections and output their content as sections and articles
{% comment %}
Loops though every collection you defined in _config.yml and grabs the pages they contain; outputting title and full text with good basic html semantics.
Use page.excerpt instead of page.content to grab the first paragraph, blog list style. Markdownify is optional, depends how you authored content in your collections; I typically use Markdown.
{% endcomment % }
{% for collection in site.collections %}
{% assign name = collection.label %}
<section>
<h1>{{ name }}</h1>
{% for page in site.[name] %}
<article>
<h2>{{ page.title }}</h2>
<p>{{ page.content | markdownify }}</p>
</article>
{% endfor %}
</section>
{% endfor %}
@wndxlori
Copy link

wndxlori commented Dec 8, 2016

Excellent. I was missing that markdownify filter and wondered why my markdown wasn't rendering properly

@aamnah
Copy link

aamnah commented Mar 13, 2017

thank you!

@mamafanfan
Copy link

line 13 the period got me an error. Liquid is happier with this {% for page in site[name] %}. Cheers!

@N02870941
Copy link

BEAUTIFUL. THANK YOU

@kyleplo
Copy link

kyleplo commented Jan 13, 2018

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