Debian Codegraph @

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

raw
1 ---
2 title: HasMenuCurrent
3 description: Reports whether the given Page object matches the Page object associated with one of the child menu entries under the given menu entry in the given menu.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: bool
9 signatures: [PAGE.HasMenuCurrent MENU MENUENTRY]
10 aliases: [/functions/hasmenucurrent]
11 ---
12
13 If the `Page` object associated with the menu entry is a section, this method also returns `true` for any descendant of that section.
14
15 ```go-html-template
16 {{ $currentPage := . }}
17 {{ range site.Menus.main }}
18 {{ if $currentPage.IsMenuCurrent .Menu . }}
19 <a class="active" aria-current="page" href="{{ .URL }}">{{ .Name }}</a>
20 {{ else if $currentPage.HasMenuCurrent .Menu . }}
21 <a class="ancestor" aria-current="true" href="{{ .URL }}">{{ .Name }}</a>
22 {{ else }}
23 <a href="{{ .URL }}">{{ .Name }}</a>
24 {{ end }}
25 {{ end }}
26 ```
27
28 See [menu templates][] for a complete example.
29
30 > [!NOTE]
31 > 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.
32
33 [menu templates]: /templates/menu/#example