Almoullim
6/20/2016 - 1:28 PM

Build Your Navigation Menu Using _data/nav.yml

Build Your Navigation Menu Using _data/nav.yml

<nav>
  <ul>
    {% for nav in site.data.nav %}
      {% if nav.subcategories != null %}
        <li>
          <a href="{{ site.url }}{{ nav.url }}">{{ nav.title }} ▼</a>
          <ul>
          {% for subcategory in nav.subcategories %}
            <li><a href="{{ site.url }}{{ subcategory.subhref }}">{{ subcategory.subtitle }}</a></li>
          {% endfor %}
          </ul>
        </li>
      {% elsif nav.title == page.title %}
         <li class="active">
           <a href="{{ nav.url }}">{{ nav.title }}</a>
         </li>
      {% else %} 
        <li>
          <a href="{{ site.url }}{{ nav.href }}">{{ nav.title }}</a>
        </li>
      {% endif %}
    {% endfor %}
  </ul>
</nav>
- title: "Home"
  href: "/"

- title: "News"
  href: "/news/"

- title: "Snippets"
  subcategories:
    - subtitle: "Example1"
      subhref: "#"
    - subtitle: "Example2"
      subhref: "#"