Skip to content

Instantly share code, notes, and snippets.

@alexcheng1982
Created April 8, 2014 21:35
Show Gist options
  • Save alexcheng1982/10196385 to your computer and use it in GitHub Desktop.
Save alexcheng1982/10196385 to your computer and use it in GitHub Desktop.
Jekyll - Bootstrap Navbar Active Status for Different Pages See http://midgetontoes.com/blog/2014/04/09/jekyll-bootstrap-navbar-active-status-for-different-pages/
module SampleApp
class ActivePageTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
name = context.environments.first["page"]["name"]
return '' if name.nil? or @text.nil?
return name == @text ? ' active ' : ''
end
end
end
Liquid::Template.register_tag('active_page', SampleApp::ActivePageTag)
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<div class="container"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class=" icon-chevron-down"></span> </a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="{% active_page index%}"><a href="index.html">Home</a></li>
<li class="{% active_page about%}"><a href="about.html">About us</a></li>
<li class="{% active_page contact%}"><a href="contact.html">Contact us</a></li>
</ul>
</div>
</div>
</div>
</div>
---
layout: page
title: Contact us
name: contact
---
Contact us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment