# Yaml front matter loop error (?)

**URL:** <https://talk.jekyllrb.com/t/yaml-front-matter-loop-error/499>\
**Category:** Help\
**Created:** [April 30, 2017, 1:02pm UTC](https://talk.jekyllrb.com/t/yaml-front-matter-loop-error/499 "2017-04-30T13:02:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sch](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@sch](https://talk.jekyllrb.com/u/sch)\
**Post date:** [April 30, 2017, 1:02pm UTC](https://talk.jekyllrb.com/t/yaml-front-matter-loop-error/499/1 "2017-04-30T13:02:13Z")

</div>

Hello jekyll-talk community!

Currently, I am trying to create a filter list that responds to some javascript. The js part is fine, I have some similar yet smaller loops that are working.  
Basically, the idea is the got a working html-link that has a href-value different to the text displayed. As all my filter links are in lowercase and the the filter option contain more than one word, I wanted to create a nested (?) yaml front matter.

Here it it is:

```
---
filters:
   - category:
     - name: "All"
     - link: "all"
   - category:
     - name: "For Women"
     - link: "women"
   - category:
     - name: "For Men"
     - link: "men"
   - category:
     - name: "Accessories"
     - link: "accessories"
   - category:
     - name: "Others"
     - link: "others"
---

```

and there is my liquid loop:

```
<ul class="categories container">
  {% for item in page.filters %}
  {% for outcome in item.category %}

  <li><a href="#{{ link.category }}">{{ name.category }}</a></li>

  {% endfor %}
  {% endfor %}
</ul>

```

After compiling, this is my html outcome.

```
    <ul class="categories container">
    <li><a href="#{"name"=>"All"}{"link"=>"all"}">{"name"=>"All"}{"link"=>"all"}</a></li>
    <li><a href="#{"name"=>"For Women"}{"link"=>"women"}">{"name"=>"For Women"}{"link"=>"women"}</a></li>
    <li><a href="#{"name"=>"For Men"}{"link"=>"men"}">{"name"=>"For Men"}{"link"=>"men"}</a></li>
    <li><a href="#{"name"=>"Accessories"}{"link"=>"accessories"}">{"name"=>"Accessories"}{"link"=>"accessories"}</a></li>
    <li><a href="#{"name"=>"Others"}{"link"=>"others"}">{"name"=>"Others"}{"link"=>"others"}</a></li>
    </ul>

```

I’ve tried many combinations/variations but this is by far the nearest I’ve come. My compilation log is also clear, no errors at this one.

Do you have any idea how I can get it to work? Thanks and greetings,

Adrian

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [April 30, 2017, 5:31pm UTC](https://talk.jekyllrb.com/t/yaml-front-matter-loop-error/499/2 "2017-04-30T17:31:53Z")

</div>

this page has some great yaml examples, link is to nested lists:

> <https://github.com/planetjekyll/quickrefs/blob/master/YAML.md#nested-list-of-keyvalue-records>

I think you could do:

```auto
- category
  - name: "All"
    link: "all"
   -name: "For Women"
    link: "women"

```

but it also depends on what all else you have under filters - if this is it, then I think you can drop the category part.

I think your liquid also needs help, you have 2 for loops - not sure why, your output isn’t what I would expect.

I think it would be more like:

```auto
<ul class="categories container">
  {% for item in page.filters.category %} 
  <li><a href="#{{ item.link }}">{{ item.name }}</a></li>
  {% endfor %}
</ul>

```

that is untested, probably not perfect, and it also depends on what the yaml really is - is it filters, or category (careful with that word as it is a thing on its own).

The link above has great examples, and just about all use cases.

---

<div class="post-metadata">

**Author:** ![sch](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@sch](https://talk.jekyllrb.com/u/sch)\
**Post date:** [April 30, 2017, 9:27pm UTC](https://talk.jekyllrb.com/t/yaml-front-matter-loop-error/499/3 "2017-04-30T21:27:27Z")

</div>

Hey rdyar,

thank you for your quick and useful reply! I’ve managed to get it to work and I’m happy with the result.  
The cheatsheet really helped, thanks again! 🙂

It is filters, but showing categories. That’s how I’d describe it.

Cheers!
