Skip to content

Instantly share code, notes, and snippets.

@bgarrant
Last active August 29, 2018 13:48
Show Gist options
  • Save bgarrant/ba21cc7363bbe06304c20d1eb68f1be6 to your computer and use it in GitHub Desktop.
Save bgarrant/ba21cc7363bbe06304c20d1eb68f1be6 to your computer and use it in GitHub Desktop.
Bootstrap 4 Navbar with Statamic 2.x CMS

Bootstrap 4 Navbar with Statamic 2.x CMS

<nav id="mainNavigation" class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarContent">
    <ul class="navbar-nav mr-auto">
      {{ nav from="/" max_depth="2" include_home="true" }}
      {{ if !children }}
      <li class="nav-item{{ if is_current }} active{{ endif }}">
        <a class="nav-link" href="{{ url }}">{{ title }}</a>
      </li>
      {{ else }}
      <li class="nav-item dropdown{{ if is_current }} active {{ endif }}">
        <a href="#" class="nav-link dropdown-toggle" href="#" id="navbarDropdown{{ id }}" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ title }}</a>
        <ul class="dropdown-menu" aria-labelledby="navbarDropdown{{ id }}">
          <li><a class="dropdown-item" href="{{ url }}">{{ title }}</a></li>
          {{ children }}
          <li><a class="dropdown-item" href="{{ url }}">{{ title }}</a></li>
          {{ /children }}
        </ul>
      </li>
      {{ endif }}
      {{ /nav }}
    </ul>
  </div>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment