2 June 2017

How-To - Jekyll Collections

Jekyll’s Collections provide powerful tools to organize content. Ben Balter put together an excellent write-up about using Collections with Jekyll. And the Jekyll documentation is super helpful as well.

Here’s what I did, to demonstrate Jekyll Collections:

  1. Create the collection folder, <source>/_my_collection_name
  2. Create some pages in <source>/_my_collection_name
  3. Add the collection config to _config.yml:
     collections:
       my_collection_name:
         output: true
         permalink: /level1/level2/:title.html
    
     defaults:
       - scope:
           path: ""
           type: my_collection_name
         values:
           layout: post
    
  4. Create a page, e.g. <source>/allcontent.md, to display all the content in the collection

     ---
     title: All the content in the collection
     layout: post
     permalink: allcontent.html
     ---
    
     {% if site.my_collection_name.size > 0 %}
         <ul>
         {% for a-content in site.my_collection_name %}
             <li>
                 <strong><a href="{{ a-content.url }}">{{ a-content.title }}</a></strong> / <time datetime="{{ a-content.date | date_to_xmlschema }}">{{ a-content.date | date: '%b %-d, %Y'}}</time>
                 {{ a-content.excerpt }}
             </li>
         {% endfor %}
         </ul>
     {% else %}
         <p>No content in this collection yet!</p>
     {% endif %}
    
comments? | contribute | tags: notes how-to jekyll