diff options
| author | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2020-09-20 19:03:43 +0530 |
|---|---|---|
| committer | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2020-09-20 19:03:43 +0530 |
| commit | 6770e5e552bc367181f3786169e614683fadeb16 (patch) | |
| tree | 17d5998ae1bde83971ab6cc18964641ed7d36cbc /layouts/partials/header.html | |
| parent | 46a092553ad84160446baa5557b68ab6f7cf4c59 (diff) | |
menu : add menu location indicator
credits for fix with [.IsMenuCurrent](https://gohugo.io/functions/ismenucurrent/): https://stackoverflow.com/a/56454338
Diffstat (limited to 'layouts/partials/header.html')
| -rw-r--r-- | layouts/partials/header.html | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 7be916c..6c02c7c 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -12,14 +12,19 @@ {{- else }} <p class="logo"><a href="{{ "" | absLangURL }}">{{ .Site.Title }}</a></p> {{- end }} - {{- if .Site.Menus.main }} + {{ $currentPage := . }} <ul class="menu" id="menu" onscroll="menu_on_scroll()"> {{- range .Site.Menus.main }} + {{ $menu_item_url := .URL | relLangURL }} + {{ $page_url:= $currentPage.RelPermalink | relLangURL }} <li> - <a href="{{ .URL | absLangURL}}">{{ .Name }}</a> + <a href="{{ .URL | absLangURL }}"> + <span {{ if eq $menu_item_url $page_url }} + {{/* the menu item links to the current page (with relLangURL) */}} class="active" + {{ end }}>{{ .Name }}</span> + </a> </li> {{- end }} </ul> - {{- end }} </nav> </header>
\ No newline at end of file |
