Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joePichardo/20799ca23fe24597e18629e414ac9396 to your computer and use it in GitHub Desktop.
Save joePichardo/20799ca23fe24597e18629e414ac9396 to your computer and use it in GitHub Desktop.
Shopify Liquid navigation using Bootstrap 4
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="{{ routes.root_url }}">Joe Pichardo</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
{% for link in linklists.main-menu.links %}
<li class="nav-item {% if link.active %}active {% if link.child_active %}child-active{% endif %}{% endif %} {% if link.links != blank %}dropdown{% endif %}">
<a class="nav-link {% if link.links != blank %} dropdown-toggle{% endif %}"
href="{{ link.url }}" {% if link.links != blank %} id="navbarDropdown-{{ link.title | downcase | replace: " ", "-" }}" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"{% endif %}>{{ link.title }} {% if link.active %}
<span class="sr-only">(current)</span>{% endif %}</a>
{% if link.links != blank %}
<div class="dropdown-menu" aria-labelledby="navbarDropdown-{{ link.title | downcase | replace: " ", "-" }}">
{% for child_link in link.links %}
<a class="nav-link dropdown-item {% if child_link.links != blank %} dropdown-toggle {% endif %}" href="{{ child_link.url }}" {% if child_link.links != blank %} id="navbarDropdown-{{ link.title | downcase | replace: " ", "-" }}" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"{% endif %}>{{ child_link.title }}</a>
{% if child_link.links != blank %}
<div class="dropdown-menu" aria-labelledby="navbarDropdown-{{ child_link.title | downcase | replace: " ", "-" }}">
{% for grandchild_link in child_link.links %}
<div class="dropdown-item">
<a class="nav-link {% if grandchild_link.active %}active {% if grandchild_link.child_active %}child-active{% endif %} {% endif %}" href="{{ grandchild_link.url }}">{{ grandchild_link.title }}</a>
</div>
{% endfor %}
</div>
{% endif %}
{% endfor %}
</div>
{% endif %}
</li>
{% endfor %}
</ul>
<form class="search form-inline my-2 my-lg-0" action="{{ routes.search_url }}" method="get" role="search">
<input
class="form-control mr-sm-2"
type="text"
placeholder="Search"
aria-label="Search"
name="q"
value="{{ search.terms | escape }}"
/>
<button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</div>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment