Debian Codegraph @

docs/content/en/methods/page/IsMenuCurrent.md

raw
1 ---
2 title: IsMenuCurrent
3 description: Reports whether the given Page object matches the Page object associated with the given menu entry in the given menu.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: bool
9 signatures: [PAGE.IsMenuCurrent MENU MENUENTRY]
10 aliases: [/functions/ismenucurrent]
11 ---
12
13 ```go-html-template
14 {{ $currentPage := . }}
15 {{ range site.Menus.main }}
16 {{ if $currentPage.IsMenuCurrent .Menu . }}
17 <a class="active" aria-current="page" href="{{ .URL }}">{{ .Name }}</a>
18 {{ else if $currentPage.HasMenuCurrent .Menu . }}
19 <a class="ancestor" aria-current="true" href="{{ .URL }}">{{ .Name }}</a>
20 {{ else }}
21 <a href="{{ .URL }}">{{ .Name }}</a>
22 {{ end }}
23 {{ end }}
24 ```
25
26 See [menu templates][] for a complete example.
27
28 > [!NOTE]
29 > When using this method you must either define the menu entry in front matter, or specify a `pageRef` property when defining the menu entry in your project configuration.
30
31 [menu templates]: /templates/menu/#example