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
-
How do I identify the current page using eleventy-navigation in a WebC component? If I use
page.url
in 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
activeListItemClass
andactiveAnchorClass
options, along witheleventyNavigationToHtml
, but it didn't work for me because$data.eleventyNavigation.key
was 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.url
on 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.js
just 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.order
order, 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:
And
/_includes/base.webc
is where I use the navigation:And the rendered
<nav>
is always this:Beta Was this translation helpful? Give feedback.
All reactions