11ty/eleventy-navigation

Empty array of navPages

kalininmax opened this issue · 3 comments

Browser:
image

I'm newbie. I used this guide.

In my md files I used front matter keys like this:

---
title: 11ty starter site
description: This is a demonstration website generated using the 11ty static site generator.
layout: base.njk
eleventyNavigation:
	key: home
	order: 100
---
---
title: About us
description: What we do.
eleventyNavigation:
	key: about
	order: 200
---
---
title: Privacy policy
description: We keep your details private.
eleventyNavigation:
	key: privacy
	parent: about
	order: 220
---
---
title: Our team
description: Information about us.
eleventyNavigation:
	key: team
	parent: about
	order: 210
---

But it return empty array (screenshots above):

{% set navPages = collections.all | eleventyNavigation %}
{{ navPages | dump | safe }}  

What's problem with eleventy navigation in my project?
Repository: https://github.com/kalininmax/11ty

Instead of using tabs in your frontmatter, try using 2 spaces:

[
  {
    "key": "home",
    "order": 100,
    "url": "/",
    "pluginType": "eleventy-navigation",
    "title": "home",
    "children": []
  },
  {
    "key": "about",
    "order": 200,
    "url": "/about/",
    "pluginType": "eleventy-navigation",
    "title": "about",
    "children": [
      {
        "key": "team",
        "parent": "about",
        "order": 210,
        "url": "/about/team/",
        "pluginType": "eleventy-navigation",
        "parentKey": "about",
        "title": "team",
        "children": []
      },
      {
        "key": "privacy",
        "parent": "about",
        "order": 220,
        "url": "/about/privacy/",
        "pluginType": "eleventy-navigation",
        "parentKey": "about",
        "title": "privacy",
        "children": []
      }
    ]
  }
]

@pdehaan thank you so much.
Actually, just now, I found this answer in Eleventy Walk Through guide. But anyway thank you for your time.
image

GRUBES commented

FWIW it looks like this occurs because of this condition. If you do not provide a specific key to eleventyNavigation, then the pages in the collection you pass cannot have a parent. Not sure whether that is intentional, but it was unexpected to me.