Skip to content

Commit

Permalink
check for active children in submenus (alshedivat#1869)
Browse files Browse the repository at this point in the history
This patch checks, if the title of the current page matches with the
title of a submenu child. If so, it sets the submenu and the
corresponding child as active, highlighting it in the header.
  • Loading branch information
Tianmaru authored Dec 25, 2023
1 parent d9f96f9 commit 3bf227f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions _includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@
{%- for p in sorted_pages -%}
{%- if p.nav and p.autogen == nil -%}
{%- if p.dropdown %}
<li class="nav-item dropdown {% if page.title == p.title %}active{% endif %}">
{%- assign has_active_child = false -%}
{%- for child in p.children -%}
{%- if page.title == child.title -%}
{%- assign has_active_child = true -%}
{%- endif -%}
{%- endfor -%}
<li class="nav-item dropdown {% if page.title == p.title or has_active_child %}active{% endif %}">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ p.title }}
{%- if page.title == p.title -%}
{%- if page.title == p.title or has_active_child -%}
<span class="sr-only">(current)</span>
{%- endif -%}
</a>
Expand All @@ -78,7 +84,7 @@
{%- if child.title == 'divider' %}
<div class="dropdown-divider"></div>
{%- else %}
<a class="dropdown-item" href="{{ child.permalink | relative_url }}">{{ child.title }}</a>
<a class="dropdown-item {% if page.title == child.title %}active{% endif %}" href="{{ child.permalink | relative_url }}">{{ child.title }}</a>
{%- endif -%}
{% endfor %}
</div>
Expand Down

0 comments on commit 3bf227f

Please sign in to comment.