Here is the liquid code:
{% for niche in site.data.navig %}
Niche ID = {{ niche.id }}
{% for group in niche.group %}
group name = {{ group.name }}
{% endfor %}
{% endfor %}
Here is the result:
Niche ID = air
group name = Grp-Name3
As can be seen, only the last group in the hierarchy is returned (the last element in the returned array). Seems Jekyll does not return proper array. Note that the code is a typical code from all Jekyll tutorials (which neglect this issue assuming only one group is allowed under niche) – I need to have multiple “group” under “niche”
I would be grateful if someone come up with a solution (either the yml file or the liquid code or both)
Hi rdyar, Your example needs its own code since it has different structure than mines. What I need a hierarchical structure (under end -name entry) not a flat structure. – Regards.
{% for niche in site.data.sections %}
Niche ID = {{ niche.id }} <br>
{% for group in niche.group %}
group name = {{ group.name }}<br>
{% endfor %}
<hr>
{% endfor %}
and got:
Niche ID = air
group name = Grp-Name1
group name = Grp-Name2
group name = Grp-Name3
Niche ID = air2
group name = Grp-Name12
group name = Grp-Name22
group name = Grp-Name32
Thanks. Your yml and code work perfect. However, as I mentioned, I need more that on group under Alir (as the yml below). The code just pick up the last group under Air and misses the first one (or any other one above the last one) – it returns only “Grp-Name-10000” which is the last one:
name: Air
id: air
page-title: page1-title
description: Decs_1
group:
then you would need to name the 2nd group something else. I don’t think you can have more than one key with the same name, that doesn’t make sense.
If they are all groups, why are they not in the first group?
Imagine yourself as the computer, how would you be able to keep track of 2 things that have the same name but then consider them as different things? If you told me last week your name is paul, and then today you tell me your name is bob, tomorrow I am going to think your name is bob. You can only have 1 name. The data can only have 1 key.
That assumes I am understanding you correctly, which I may not be.
Thanks for your comment. It makes sense. As a matter of fact, I understand I need to create a collection of “groups” (one collection per each level of hierarchy). So I’m building the whole structure on this concept.
Regards, Behrouz