Kelly Goedert
Kelly Goedert

Reputation: 1067

Show a collection of values in jekyll

Is it possible to have a collection of values in jekyll and then format them as table?

I tried something like this in my .md file:

---
layout: tutorial
title: Jekyll
reqs:
 - name: names here
   desc: description here
   value: value
 - name: names here
   desc: description here
   value: value
---

In my tutorial layout I have this:

---
layout: home
---

{% for item in page.reqs %}
  {{ item.name }}
  {{ item.desc }}
  {{ item.value }}
{% endfor %}

The html code for the table was removed. The problem is my for loop prints nothing. The page is empty except for what was inherited from the other layout.

Upvotes: 0

Views: 495

Answers (1)

Andrew Clark
Andrew Clark

Reputation: 731

Looks like a YAML problem. You're mixing up the array and dictionary syntaxes. Try something like this instead:

---
layout: tutorial
title: Jekyll
reqs:
 - item1:
     name: names here
     desc: description here
     value: value
 - item2:
     name: names here
     desc: description here
     value: value
---

Now your for loop is looping through an array of dictionaries (item1, item2...) whose values you can use in your output.

Upvotes: 1

Related Questions