List collections items in the layout


I’m trying to display a list of items from collections on a website. I’d like to use one layout and write in the front matter the name of the category so it displays in the page the name and URL of every pages belonging to this collection.

This is my code at the moment:

 {% for collection_name in site.collection_names %}
   <a href="{{ collection_name.url }}" class="btn btn-full btn-primary">{{ collection_name.title }}</a>
{% endfor %}

Does someone have a solution?

I’m using Jekyll 3.8.5, and due to Github Pages plugin I can’t use Jekyll 4.0 for now.


collection_names is the actual name of the collection?

What happens when you run that? nothing? are you sure you have collections setup correctly? are they outputting to where you told them to (if you have output true).

A little more info like what you have in your config and what is in the collection would be good. Link to repo even better.

No collection_name is just an example.
This works, but I have to put it in every category list pages with replacing the name of the category. The config file is good, everything set to output: true. I tried to do it like this:

{% for {{page.collection_name}} in site.{{page.collection_name}}s %}

but of course it didn’t work.

This is the link to the repo:

you can’t do it like that - the word after For is the iterator (?) and is just a word - I prefer item as it makes it more clear what it is.

I think you need to do a where in the second part or maybe do an assign with a where first to limit the set, then iterate of the limited set.