Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation plugin not picking up my collections tag #53

Open
cybergrrl opened this issue Oct 9, 2020 · 2 comments
Open

Navigation plugin not picking up my collections tag #53

cybergrrl opened this issue Oct 9, 2020 · 2 comments

Comments

@cybergrrl
Copy link

I am trying to get to grips with the navigation plugin. i have successfully set it up according to here using {{ collections.all | eleventyNavigation | eleventyNavigationToHtml | safe }} {{ content | safe }}

However, the page also states that:

you can also pass any collection into eleventyNavigation. It doesn’t have to be collections.all!

I want a page to display a navigation menu only showing the pages i have tagged with mytag. But when I try
{{ collections.mytag | eleventyNavigation | eleventyNavigationToHtml | safe }} {{ content | safe }}
the navigation disappears from my page instead of showing me a navigation menu for pages in the mytag collection. There is nothing where the navigation should be.

I have several pages with the following line in the front matter: tags: mytag

When i iterate over the mytag collection, i can see that the pages are correctly added. So the problem must be with how i call the navigation plugin. Am I missing a step?

Any suggestions much appreciated.

@jordanriii
Copy link

@cybergrrl not sure what your template code and post code looks like so I'm shooting in the dark here. but I managed to get it working by making sure to change the for loop to have the name of the collection and being sure to include the eleventyNavigation and Key included in the front matter of your posts in that collection.

here is an example

This is found in the page template

  <nav>
        <ul class="nav">
            {%- for entry in collections.blog | eleventyNavigation %}
              <li class="nav-item{% if entry.url == page.url %} nav-item-active{% endif %}"><a href="{{ entry.url | url }}">{{ entry.title }}</a></li>
            {%- endfor %}
            </ul>
    </nav>

And on the front matter of a post I have included the key and the tag. Well I guess the tag could be put into a json file in that directory

---
eleventyNavigation:
    key: blog
tags:
  - blog

---

This worked in my test. Hope it helps.

@GRUBES
Copy link

GRUBES commented Sep 29, 2023

Encountering this same issue right now. eleventyNavigation works great as long as I pass in collections.all, but trying any other populated collection results in an empty Array output from eleventyNavigation.

{{ collections.all | eleventyNavigation }} # works as expected
{{ collections.nav-main | log }} # prints one element to the console/page
{{ collections.nav-main | eleventyNavigation | log }} # prints empty Array to the console and nothing on the page

@zachleat zachleat transferred this issue from 11ty/eleventy Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants