# \[SOLVED\] Listing pages of a collection

**URL:** <https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011>\
**Category:** Help\
**Created:** [September 27, 2017, 12:06pm UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011 "2017-09-27T12:06:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [September 27, 2017, 12:06pm UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/1 "2017-09-27T12:06:01Z")

</div>

I had a bizarre and large draft here about how to interpret the documentation page concerning [collections](https://jekyllrb.com/docs/collections/) that I’ve been feeding the last four days… but that was deleted and I’ll try to limit this topic to the problem I’m facing: collections not working as expected (after reading - again and again - the documentation).

**Desired result**.

1 - A directory to the custom collections  
2 - each collection’s directory should start with an `_` (underscore)  
3 - loop through and list the files of a collection in a page of another collection

**1** - Added the following to `_config.yml`:

```auto
collections:
  collections_dir: _collections

```

**2** - Somehow Jekyll wouldn’t build anything inside a directory prefixed with an underscore, at least until they were “included” as following:

```auto
include: ['_collections', '_pages', '_projects']

```

Where  
`_collections`: the directory to keep collections organized.  
`_pages`: the place to static general pages (like “about”, “contact”, listing categories etc).  
`_projects`: a collection with pages that just don’t match the general purpose of `_pages`.

**3** - I cannot get a list of the files (title and url) inside `_projects`. All pages exists. In the `_config.yml`, the permalink is set as:

```auto
permalink: :slug/

```

And all pages have something like this in their front-matter:

```auto
permalink: /manually-added-slug/

```

All pages can be acceded as [http://localhost:4000/manually-added-slug/](http://localhost:4000/manually-added-slug/). This was the only way I founded to solve [the permalink issue](https://talk.jekyllrb.com/t/permalink-variables-not-working/991).

Basically, inside `_collections/_pages/projects.md`, I’m trying to get something like this to work:

```auto
 <ul>
{% for project in site.projects %}
    <li>
      <a href={{ project.path }}">- {{ project.name }}<a/>
    </li>
  {% endfor %}
 </ul>

```

But keeping in mind that that is just an example… since many different things were tried there without success. 😉

* * *

That’s with Jekyll 3.6.0 (but not declared in the `Gemfile`), in Archlinux with Bundler version 1.15.4.  
And just for the sake of… well… here is the gem file content:

```auto
source "https://rubygems.org"
gemspec

```

Thanks in advance for any given direction. 😃

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [September 27, 2017, 12:46pm UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/2 "2017-09-27T12:46:45Z")

</div>

I think your issue is how you’re naming the collections and configuring them in your `_config.yml`.

I haven’t used the new feature that allows you specify a collections dir, but from your example above for projects… `projects.md` isn’t technically a collection, it’s a document in a `_pages` collection.

If you want a “projects” collection then it needs to be `_collections/_projects/whatever.md`. Then you’ll be able to access the documents inside of it with `site.projects`. That is if you’ve also configured them to output:

```auto
collections:
  projects:
    output: true
    permalink: # your permalink structure eg. /:collection/:path/

```

Collections need to be named with an `_` underscore, be in the root of your project (or in another folder if you’re using `collections_dir`).

---

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [September 28, 2017, 8:14am UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/3 "2017-09-28T08:14:46Z")

</div>

Hey @mmistakes, as always, thank you!

> I think your issue is how you’re naming the collections and configuring them in your \_config.yml.

Good point, I feel that I’m missing and overdoing something here.

I did tried your suggestion, but without luck.

Most of the resources concerning this I’ve found mention the `permalink:`, but I don’t understand why, since I’m setting it globally in the config. And another issue is, why is it necessary to first include the repositories prefixed with underscore? AFAIK, they should [not be ignored](https://github.com/jekyll/jekyll/issues/4965#issuecomment-222527922)…

Thanks anyway. (:

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [September 28, 2017, 9:47am UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/4 "2017-09-28T09:47:46Z")

</div>

@lsrdg configuring `collection_dir` is not available in `3.6.0`. Its slated for `v3.7.0`

The online documentation at `jekyllrb.com` is at times way ahead of time…(mirroring the `master` branch) and not particularly aligned to the latest public release.  
I agree this is an issue… but that’s for another time…

---

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [September 28, 2017, 10:51am UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/5 "2017-09-28T10:51:22Z")

</div>

Thanks, @ashmaroli! And no worries, I’ve decided to use that just because it was an interesting idea, and I’m glad it will come with `3.0.7`.

Anyway, I still don’t understand why I can’t a list of files inside a folder (a collection folder), despite of moving the collections back to the root of the project(?), and why do the repositories prefixed with an underscore need to be `include:`ed.

Should I maybe define the path on the `defaults:` (and `scope` and `values` etc…)?

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [September 28, 2017, 11:04am UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/6 "2017-09-28T11:04:28Z")

</div>

how does your **current** collections configuration look like…? (you can use dummy names for privacy)

---

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [September 28, 2017, 12:10pm UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/7 "2017-09-28T12:10:56Z")

</div>

The lines of `_config.yml` concerning collections as after trying @mmistakes idea:

```
permalink: :slug/

include: ['_pages', '_projects']

collections:
  _pages:
    output: true
    permalink: :slug/
  _projects:
    output: true
    permalink: :slug/

```

I tried with and without those fields, combining them, omitting some of them etc. (:

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [September 28, 2017, 1:20pm UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/8 "2017-09-28T13:20:05Z")

</div>

omit the trailing underscore in your collection configuration, and be mindful of the indentation (no tabs only spaces, in multiples of two)

```auto
permalink: :slug/

# not required..
# include: ['_pages', '_projects']

collections:
  pages:
    output: true
    permalink: :slug/
  projects:
    output: true
    permalink: :slug/

```

---

<div class="post-metadata">

**Author:** ![lsrdg](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lsrdg/32/431_2.png) [@lsrdg](https://talk.jekyllrb.com/u/lsrdg)\
**Post date:** [September 28, 2017, 1:52pm UTC](https://talk.jekyllrb.com/t/solved-listing-pages-of-a-collection/1011/9 "2017-09-28T13:52:05Z")

</div>

😮

It’s done! Topic marked as “solved”. Thanks, @ashmaroli for helping here!

Apparently, when I tried to set it that way, my collections were inside the `collections_dir:` and wouldn’t work anyway. Despite of that, my indentation was broken on its second level, and I won’t even mention the html syntax erros that became evident after I got the list outputted.

Thanks again to @mmistakes and @ashmaroli for taking the time and for all the questions I’ve never asked simply because you guys have already answered them somewhere else. (:
