MaximeHeckel
MaximeHeckel

Reputation: 448

Jekyll loops for posts and other section

I use Jekyll for more than 3 month now. I have made several blogs with it, but I have one question I couldn't find the answer anywhere.

In order to render all your posts , all the markdown files in the _posts, I use a for loop like this one for instance :

{% for post in site.posts %}
    {{post.title}}
{% endfor %}

I want to do the same with my projects. I created a _projects folder and tried to render them by using :

{% for project in site.projects %}
   {{project.title}}
{% endfor %}

But Jekyll doesn't seem to recognize the _projects folder. What should I do to get the same results ?

Upvotes: 4

Views: 821

Answers (2)

konus
konus

Reputation: 1622

Now we have Jekyll Collections

"Add the following to your site’s _config.yml file, replacing my_collection with the name of your collection."

For example you should add:

collections:
- projects

Then of course, you could use it in your template in the most easy way:

{% for project in site.projects %}
   {{project.title}}
{% endfor %}

Upvotes: 1

Patrick Oscity
Patrick Oscity

Reputation: 54734

This is not the way custom post types work in Jekyll. You can however put a _posts directory in another directory and build custom categories this way.

Suppose you would have your projects organized under projects/_posts, then your template would have to look something like this:

{% for post in site.categories.projects %}
  {{ post.title }}
{% endfor %}

Found it in Jekyll's Github Issues

Upvotes: 6

Related Questions