I’m using (non-content) entries to add a single-level menu via config.toml. All works well — thanks for making menus happen Hugo crew. I’d love to remove/exclude the current page from the menu (it’s arguably wasted space and UI given the visitor is already viewing that page). Is this possible?
Have a look at the IsMenuCurrent function and the rendering menus example in the docs.
Thanks for the reply @digitalcraftsman. I have looked at the examples and the code is a bit beyond me. Any guides will be gratefully appreciated.
The following snippet shows all menu entries of a site except the one for the current site. Replace main
in .Site.Menus
and .IsCurrentMenu "main" .
if your menu has a different name.
{{ $currentNode := . }}
{{ range .Site.Menus.main }}
{{ if not ($currentNode.IsMenuCurrent "main" .) }}
<a href="{{ .URL }}"> {{ .Name }} </a>
{{ end }}
{{ end }}