Skip to content

Instantly share code, notes, and snippets.

@dsadhanala
Last active August 29, 2015 14:10
Show Gist options
  • Save dsadhanala/cada97b677d00d327b4e to your computer and use it in GitHub Desktop.
Save dsadhanala/cada97b677d00d327b4e to your computer and use it in GitHub Desktop.
Jade Snippet: Navigation iterator
//- compile and see the output online at below URL
http://jade-lang.com/
//- navigation data
-var navLinks = { 'Home': 'home.html', 'About': 'about.html', 'Services': 'services.html', 'Contact': 'contact.html'};
//- set default selected item (useful for adding active state for current page navigation link in each page)
- var activeLink = 'Home';
nav(role="navigation" aria-label="Primary")
ul.site-primary-nav
//- iterator
each val, key in navLinks
li.nav__link
//- check for acive link and add class
if activeLink === key
- activeLink = "nav__link-active"
else
- activeLink = ""
//- populate links
a(href=val class="#{activeLink}")= key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment