Using Jekyll 3.8.5 (for Github pages).
I have set up a collection _resources, which contains files like this:
---
title: Resource 1
categories:
- title: cat3
level: 1
- title: cat2
level: 2
---
I am using a simple Liquid for loop iterate through the categories and their data:
<ul>
{% for category in resource.categories %}
<li> Category: {{ category.title }} | Level: {{ category.level }}</li>
{% endfor %}
</ul>
The expected result should be:
<ul>
<li> Category: cat3 | Level: 1</li>
<li> Category: cat2 | Level: 2</li>
</ul>
Instead, I am getting extra <li>
elements:
<ul>
<li> Category: cat3 | Level: 1</li>
<li> Category: cat2 | Level: 2</li>
<li> Category: | Level: </li>
<li> Category: | Level: </li>
</ul>
I checked using {{ categories.size }}
and it returned 4
So, I'm sure I'm doing something wrong with my YAML formatting, for Jekyll to think there are two extra categories.
I've tried removing the hyphens in the YAML, but Jekyll throws an error:
no implicit conversion of Hash into Array
Any help very gratefully received.
Thanks,
Mark