4

Following the Jekyll Collections documentation, I wrote the following code in _config.yml

_config.yml

collections: 
- popular_posts

So when I print {{ site.collections }}, the output is "popular_posts".

I also made a folder called "_popular_posts" at the same level as "_posts". _popular_posts contains two .md files with some YAML front matter, same as a post.

However, if I print {{ site.popular_posts }} or {{ site.collections.popular_posts }}, there is no output.

How do I have Jekyll recognize the .md files in that directory so that the following code will work?

{% for popular_post in site.popular_posts %}
  <a href="{{ popular_post.link }}">
    <h1>{{ popular_post.title }}</h1>
    <img class="pop-img" src="{{ popular_post.image_url }}">
  </a>
  <span id="pop-order"><span class="pop-current-popular_post-number">{{ popular_post.number }}</span>/5</span>
{% endfor %}
DSS
  • 43
  • 4
  • Did you set `output:` to `true`? I don't fully understand collections, but as I understand it, that is required to make Jekyll generate the collection items. Also note that the collections functionality is said to be in beta, and may not be fully functional yet. – Rudy Velthuis Jun 18 '14 at 06:32

1 Answers1

5

It's quite easy! You're on the right track. In your _config.yml:

collections:
- popular_posts

This will tell Jekyll to read in all the files in _popular_posts.

If you want each of those two files to have a corresponding output file (like how _posts works now), you'll want to change your _config.yml to:

collections:
  popular_posts:
    output: true

This will produce files at /popular_posts/filename1.html and /popular_posts/filename2.html, one page for each post.

Collections are only recently up on GitHub Pages so if you were trying this there, it would have failed.

Check out jekyll-help for more help if you need it!

parkr
  • 803
  • 6
  • 14