Highlight which page is currently active. #44

Closed
opened 2022-11-10 10:31:08 +00:00 by halfd · 4 comments
Owner

Show which page the visitor is on, by highlighting it in the menu.

Show which page the visitor is on, by highlighting it in the menu.
halfd added the
new-website
ui
labels 2022-11-10 10:31:08 +00:00
halfd self-assigned this 2022-11-10 10:31:08 +00:00
benjaoming was assigned by halfd 2022-11-11 14:15:13 +00:00
halfd removed their assignment 2022-11-11 14:15:21 +00:00
Author
Owner

I can't figure out how to do it in hugo :D

I can't figure out how to do it in hugo :D
Owner
https://discourse.gohugo.io/t/another-way-to-make-a-menu-item-active/17029 has something
Owner

Yup, I think that this is the one we want:

{{ range . }}
  {{ $active := eq $.RelPermalink (.URL | relLangURL) }}
  {{ $active = or $active (eq $.Section (lower .Name)) }}
  <li>
    <a href="{{ .URL | relLangURL }}"{{ if $active }} class="active"{{ end }}>{{ .Name }}</a>
  </li>
{{ end }}
Yup, I think that this is the one we want: ``` {{ range . }} {{ $active := eq $.RelPermalink (.URL | relLangURL) }} {{ $active = or $active (eq $.Section (lower .Name)) }} <li> <a href="{{ .URL | relLangURL }}"{{ if $active }} class="active"{{ end }}>{{ .Name }}</a> </li> {{ end }} ```
Owner

Ah yeah btw @halfd the change just adds a CSS class "active" to the menu item, but it doesn't actually style it :)

Ah yeah btw @halfd the change just adds a CSS class "active" to the menu item, but it doesn't actually style it :)
Sign in to join this conversation.
No Label
new-website
ui
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: data.coop/website#44
No description provided.