# List collection with name from front matter

**URL:** <https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619>\
**Category:** Help\
**Created:** [November 20, 2019, 10:18pm UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619 "2019-11-20T22:18:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pfeifakopf](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@Pfeifakopf](https://talk.jekyllrb.com/u/Pfeifakopf)\
**Post date:** [November 20, 2019, 10:18pm UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619/1 "2019-11-20T22:18:58Z")

</div>

Hi, I want to list different nested collections. The sub collection name should be loaded dynamically from the parent collection front matter.

```auto
Data structure:
_parents/parent.md
_dynSub/sub.md

```

\_parent/parent.md

```auto
---
title: Parent
sub: dynSub
order: 01
---

```

Template:

```auto
{% assign parents = site.parents | sort: 'order' %}
{% for parent in parents %}

<section id="{{ parent.title | slugify }}" class="section">
  <h2>{{ parent.title }}</h2>

  {% for dynSubItem in site.parent.sub %}

    {{ dynSubItem.title }} 

  {% endfor %} 

</section>
{% endfor %} 

```

But his doesn’t work. Could someone help please a jekyll beginner? Thanks!

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [November 21, 2019, 12:02am UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619/2 "2019-11-21T00:02:49Z")

</div>

I don’t think that is going to work, it looks like you are trying to tell jekyll that site.parents.sub is dynsub, but that is really a page variable not a site variable, at least I think that is what you are trying to do.

Is the `parents` collection going to have multiple files with sub: dynSub? you might be able to do the outer loop like you have, and then make an inner loop that looks at the page variable item.sub?

Not sure, there is not a lot of info to go on to show what you want to do.

Also, naming the folders parent and sub is confusing, is it really called parent? or are you calling it parent cause it is the parent folder? something more real world might be easier for us to tell what is going on.

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [November 21, 2019, 12:07am UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619/3 "2019-11-21T00:07:32Z")

</div>

this sounds sort of like what you want, though I can’t say I followed exactly what they were saying to do:

> <https://stackoverflow.com/questions/37277738/can-i-create-nested-collections-in-jekyll>

and maybe:

> [@Looping through a sub collection or sub directory in a collection](https://talk.jekyllrb.com/t/looping-through-a-sub-collection-or-sub-directory-in-a-collection/1324/10):
>
> @mmistakes Very cool. So this loops through all with grouped\_by articles, stuffs them in an array. Then, it uses that assignment in the for loop. Thanks. Also, nice to know that Collection docs don’t have the same support for categories as posts. Maybe in the future it will. crossed_fingers:t4@rdyar Yes, that sounds like it could also reduce the amount of work stuffing the category or group in the defaults array. I assume you mean this: \_config.yml: defaults: - scope: path: "" # a…

---

<div class="post-metadata">

**Author:** ![Pfeifakopf](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@Pfeifakopf](https://talk.jekyllrb.com/u/Pfeifakopf)\
**Post date:** [November 21, 2019, 2:25am UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619/4 "2019-11-21T02:25:52Z")

</div>

Hi @rdyar

thanks for your time. I try, to explain it better. I want to build a bigger one page website with fullpage.js.  
The “parents” should be looping through vertical sections (parent-01,parent-02,etc…)  
Inside the parent section i want to move horizontal and choose in the parent section, which collection should be looped as children.

**Example:**

```auto
services
  service-01 – service-02 – service-03 – service-04 – service-05
references
  project-01 – project-02 – project-03 – project-04 – project-05
team
  no children
company
  info-01 – info-02 – info-03 – info-04 – info-05

```

So i thought, i build for the children separate collections and show them inside the parent.

**Vertical sections**

```auto
_sections
  - services.md
  - references.md
  - team.md
  - company.md

```

**Horizontal children**

```auto
_services
  - service-01.md
  - service-02.md
  - ...
_references
  - project-01.md
  - project-02.md
  - ...
...

```

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [November 21, 2019, 4:08am UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619/5 "2019-11-21T04:08:44Z")

</div>

to me that looks like a normal set of collections - services, references, team and company are collections, so you loop thru each collection and show each collections items.

You could have a collection called `services` and a page called services.md, on that page you would loop thru all the services collection documents which would be `service-01.md – service-02.md – service-03.md – service-04.md – service-05.md`

I’m not familiar with fullpage.js or one page sites in general, so not sure if that requires something else? maybe my outline is ok except the services page can’t be a separate page? you need it to be all listed in one place with all collections together?

---

<div class="post-metadata">

**Author:** ![Pfeifakopf](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@Pfeifakopf](https://talk.jekyllrb.com/u/Pfeifakopf)\
**Post date:** [November 22, 2019, 8:37am UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619/6 "2019-11-22T08:37:31Z")

</div>

rdyar, thanks for your time. If i understand you correct, with your solution i would have no content for the parents and just get the contents from the children. Anyway, i found a solution, that works.

In the parent i can know define the child-collection-name as param, like: col: col-name  
Inside the parent loop i can show the child collection with this code:

```auto
{% assign col = section.col %}
{% for col in site.[col] %}
<div class="child">
    <h2>Col: {{ col.title }}</h2>
</div >
{% endfor %}

```

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [November 22, 2019, 4:42pm UTC](https://talk.jekyllrb.com/t/list-collection-with-name-from-front-matter/3619/7 "2019-11-22T16:42:07Z")

</div>

> [@Pfeifakopf](#):
>
> your solution i would have no content for the parents

correct, you could get that from a data file or maybe something else.

if it works it works!
