List collection with name from front matter

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

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

_parent/parent.md

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

Template:

{% 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!

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.

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

and maybe:

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:

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

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

Horizontal children

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

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?

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:

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

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

if it works it works!