Identify eleventy-navigation page in a WebC component? #3406
Unanswered
VAggrippino
asked this question in
Q&A
Replies: 1 comment
-
|
I got it to work using I don't really want to close this discussion, though. I think the way I was trying to do it is consistent with the documentation. Did I discover a bug or just misunderstand the docs? Did I miss some documentation? I don't even know where I got that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How do I identify the current page using eleventy-navigation in a WebC component? If I use
page.urlin awebc:if, the value is always the same no matter what input file it's rendering.The documentation for eleventy-navigation has examples for Liquid or Nunjucks that I thought would translate pretty easily to WebC.
I tried the
activeListItemClassandactiveAnchorClassoptions, along witheleventyNavigationToHtml, but it didn't work for me because$data.eleventyNavigation.keywas always set to the value from the first file according toeleventyNavigation.order(Home, in this case). This kinda makes sense if it only processes and renders the component once, for the first file, and then re-uses what's already rendered.Using my example code below, it identifies
/projects/aspage.urlon all the rendered pages. This makes less sense to me because it's not the first or the last value in the object. If it went by file name, key order, or the order I set witheleventyNavigation.order, it would be the second to last.I added a
console.log()to/node_modules/@11ty/eleventy-navigation/eleventy-navigation.jsjust in case it was processing the Projects key first. Every time I run it the values in the object match the order of the file names (alphabetical). This is different from myeleventyNavigation.orderorder, but Projects is second-to-last in either case.I'd love to understand what's going on here and learn the right way™ to do this.
/_components/main-nav.webc:My folder structure is as simple as possible:
This is just a reproduction of the problem, so the root files are all pretty much like this:
--- layout: base.webc eleventyNavigation: key: Blog order: 1 --- <h2>Blog</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nisi placeat provident nemo expedita incidunt alias ullam eligendi, inventore a beatae laborum ducimus laboriosam aliquid aliquam, totam, est veniam animi pariatur!</p>And
/_includes/base.webcis where I use the navigation:And the rendered
<nav>is always this:Beta Was this translation helpful? Give feedback.
All reactions