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 ?
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
Now we have Jekyll Collections
"Add the following to your site’s
_config.yml
file, replacingmy_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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With