Loop in loop doesn't work

I want to make every member loop firstly, then their inner social icon loop. already I tried but didn’t work.

YAML
Screenshot_8

liquid

Screenshot_10

and then this :slight_smile:

The inner loop, loops over member.s-item, but I don’t see a field called s-item in the YAML?

1 Like

You have a couple of problems.
The Error message from Jekyll indicates the first issue Error: mapping values are not allowed in this context at line 3 column 11

If you look at your _data/teams.yml and line 3 you have incorrectly indented social under position and the icon and link lines as well. Remove the indent so it’s not a child of position and add indents to icon and link like this:

- name: Catherine J. Hanshaw
  position: CEO & Founder
  social:
    - icon: hi
      link: hello
    - icon: hi
      link: hello
- name: Another Name
  position: CTO
  social:
    - icon: hi
      link: hello
    - icon: hi
      link: hello

This will stop the error message but won’t output the correct data used in your for loops. As noted by @chuckhoupt, you’re trying to access fields that don’t exist in the second loop.

You’ll want to do something like this instead:

{% for member in site.data.teams %}
  {{ member.position }}
  {{ member.name }}

  {% for s-item in member.social %}
    <a href="{{ s-item.link }}">{{ s-item.icon }}</a>
  {% endfor %}
{% endfor %}
1 Like

Thank you so much for this, i tried it as you said. & finally worked done.:heart_eyes: