1

I'm having a little bit of a hard time getting my head around accessing some nested data with Jekyll. I'm hoping someone can help me out. I'm trying to access data within a prototypes.yml file. It's for populating cards on a dashboard. When I run the loop, however, nothing gets returned. My guess is I'm not targeting the details correctly, but ultimately I'm at a bit of a loss.

prototypes.yml

ios:
  details:
    -
      category: "category"
      title: "title"
      desc: "desc"
      author: "Sean"
      update: "12 Feb 2020"

android:
  details:
    -
      category: "category"
      title: "title"
      desc: "desc"
      author: "Sean"
      update: "12 Feb 2020"

HTML

{% for row in site.data.prototypes %}
  {% for detail in row.details %}
  <a href="{{ detail.permalink }}" class="c-card c-card--{{ detail.category }}">
    <h2>{{ detail.title }}</h2>
    <p>{{ detail.desc }}</p>
    <span>{{ detail.update }}</span>
  </a>
  {% endfor %}
{% endfor %}

1 Answer 1

1

row contains two values, the key (e.g. ios) and its value. So you'll need

{% for row in site.data.prototypes %}
  {% for detail in row[1].details %}
  <a href="{{ detail.permalink }}" class="c-card c-card--{{ detail.category }}">
    <h2>{{ detail.title }}</h2>
    <p>{{ detail.desc }}</p>
    <span>{{ detail.update }}</span>
  </a>
  {% endfor %}
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.