Debian Codegraph @

docs/content/en/methods/menu-entry/Page.md

raw
1 ---
2 title: Page
3 description: Returns the Page object associated with the given menu entry.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Page
9 signatures: [MENUENTRY.Page]
10 ---
11
12 Regardless of how you [define menu entries][], an entry associated with a page has access to its [methods][].
13
14 In this menu definition, the first two entries are associated with a page, the last entry is not:
15
16 {{< code-toggle file=hugo >}}
17 [[menus.main]]
18 pageRef = '/about'
19 weight = 10
20
21 [[menus.main]]
22 pageRef = '/contact'
23 weight = 20
24
25 [[menus.main]]
26 name = 'Hugo'
27 url = 'https://gohugo.io'
28 weight = 30
29 {{< /code-toggle >}}
30
31 In this example, if the menu entry is associated with a page, we use page's [`RelPermalink`][] and [`LinkTitle`][] when rendering the anchor element.
32
33 If the entry is not associated with a page, we use its `url` and `name` properties.
34
35 ```go-html-template
36 <ul>
37 {{ range .Site.Menus.main }}
38 {{ with .Page }}
39 <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
40 {{ else }}
41 <li><a href="{{ .URL }}">{{ .Name }}</a></li>
42 {{ end }}
43 {{ end }}
44 </ul>
45 ```
46
47 See the [menu templates][] section for more information.
48
49 [`LinkTitle`]: /methods/page/linktitle/
50 [`RelPermalink`]: /methods/page/relpermalink/
51 [define menu entries]: /content-management/menus/
52 [menu templates]: /templates/menu/#page-references
53 [methods]: /methods/page/