I have simple question about adding a class to the current menu item.
I have the following page structure:
- index.jade
- about.jade
- articles/
- _data.json
- index.jade
- blog-post-1.jade
- blog-post-2.jade
- contact.jade
Now I created a class called: .active
and it only works on the root pages (index, about and contact) but when I click on /articles
the active class is not being added to the articles li
in the menu.
I am using this code snippet from the Harp site:
ul
li(class="#{ current.source == 'index' ? 'active' : '' }")
a(href="/") Home
li(class="#{ current.source == 'about' ? 'active' : '' }")
a(href="/about") About
li(class="#{ current.source == 'articles' ? 'active' : '' }")
a(href="/articles") Articles
li(class="#{ current.source == 'contact' ? 'active' : '' }")
a(href="/contact") Contact
No matter what I try I can't seem to get the .active
menu class to work on /articles
nor any of the article pages: articles/blog-post-1
or articles/blog-post-2
and so on.
Also on the Harp site I saw you can add:
{
path: ["articles", "hello-world"],
source: "hello-world"
}
But I am not sure where to add it. I added it to the articles/_data.json
file but didn't work.