Lego2012
9/26/2016 - 9:21 PM

Navigation on Home and Back for Others

Navigation on Home and Back for Others

<!-- 
Assuming that the link to your "Home"-page (index.html) is the first array part inside the _config.htmls navigation array, you can use the following snippet to show the navigation to the different pages on the main/home page and a link back to the home page on all other pages: 
-->

<nav>
  <ul class="grid">
    {% assign url = page.url | remove:'/index.html' %}
    {% assign home = site.navigation.first %}
    {% if url == empty %}
      {% for link in site.navigation %}
        {% assign state = '' %}
        {% if page.url == link.url %}
          {% assign state = 'active ' %}
        {% endif %}
        {% if home.url != link.url %}
          <li class="{{ state }}nav-item">
              <a href="{% if page.url == link.url %}{{ site.baseurl }}{% else %}{{ site.baseurl }}{{ link.url }}{% endif %}" title="{{ link.title }}">{{ link.text }}</a>
          </li>
        {% endif %}
      {% endfor %}
    {% else %}
      <li class="nav-item active">
          <a href="{{ home.url }}" title="{{ home.title }}">{{ home.text }}</a>
      </li>
    {% endif %}
  </ul>
</nav>