Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:15:49+00:00 2026-05-29T05:15:49+00:00

I am using github to host a static site and Jekyll to generate it.

  • 0

I am using github to host a static site and Jekyll to generate it.

I have a menu bar (as <ul>) and would like the <li> corresponding to the current page to be assigned a different class for CSS highlighting.

So something like pseudo code:

<li class={(hrefpage==currentpage)?"highlight":"nothighlight"} ...>

Or perhaps even generate the whole <ul> in Jekyll.

How can this be done with minimal changes outside of the offending <ul>?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:15:49+00:00Added an answer on May 29, 2026 at 5:15 am

    Yes you can do this.
    To accomplish this we will take advantage of the fact that the current page is always represented by the liquid variable: page in the template, and also that each post/page has a unique identifier in its page.url attribute.

    This means that we just have to use a loop to build our navigation page, and by doing so we can check page.url against every member of the loop. If it finds a match, it knows to highlight that element. Here we go:

      {% for node in site.pages %}
        {% if page.url == node.url %}
          <li class="active"><a href="{{node.url}}" class="active">{{node.title}}</a></li>
        {% else %}
          <li><a href="{{node.url}}">{{node.title}}</a></li>
        {% endif %}
      {% endfor %}
    

    This works as expected. However you probably don’t want all your page’s in your nav bar. In order to emulate page “grouping” you can something like this:

    ## Put the following code in a file in the _includes folder at: ./_includes/pages_list
    
    {% for node in pages_list %}
      {% if group == null or group == node.group %}
        {% if page.url == node.url %}
          <li class="active"><a href="{{node.url}}" class="active">{{node.title}}</a></li>
        {% else %}
          <li><a href="{{node.url}}">{{node.title}}</a></li>
        {% endif %}
      {% endif %}
    {% endfor %}
    {% assign pages_list = nil %}
    {% assign group = nil %}
    

    Now pages can be “grouped”. To give a page a group you need to specify it in the pages YAML Front Matter:

    ---
    title: blah
    categories: blah
    group: "navigation"
    ---    
    

    Finally you can use your new code!
    Wherever you need your navigation to go in your template, simply “call” your include file and pass it some pages and the group you want to display:

    <ul>
      {% assign pages_list = site.pages %}
      {% assign group = 'navigation' %}
      {% include pages_list %}
    </ul>
    

    Examples

    This functionality is part of the Jekyll-Bootstrap framework.
    You can see exact documentation for the code outlined here: http://jekyllbootstrap.com/api/bootstrap-api.html#jbpages_list

    Finally you can see it in action within the website itself. Just look at the righthand navigation and you will see the current page is highlighted in green: Example highlighted nav link

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not using github. We have git setup on our machine. I created
I'm using github to store my PowerShell profile. I found posh-vcs that I'd like
I have been using git and github with my small team of developers for
I have been using https://github.com/Redth/APNS-Sharp to send push notification message to all devices where
I have this NodeJS snippnet : require('http').get({ secure: true, host: 'github.com', method: 'GET', path:
I'm using github as a repo for a little project, but I'd also like
I have a repository in which I edited file online using github online editor.
I'm using http://github.com/lakshmivyas/hyde to generate my website, and it included .htaccess mod_rewrite rules, but
I'm using http://github.com/lakshmivyas/hyde to generate my website, and it included .htaccess mod_rewrite rules, but
I'm using http://github.com/lakshmivyas/hyde to generate my website, and it included .htaccess mod_rewrite rules, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.