mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
53
docs/content/en/methods/menu-entry/Page.md
Normal file
53
docs/content/en/methods/menu-entry/Page.md
Normal file
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: Page
|
||||
description: Returns the Page object associated with the given menu entry.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: page.Page
|
||||
signatures: [MENUENTRY.Page]
|
||||
---
|
||||
|
||||
Regardless of how you [define menu entries], an entry associated with a page has access to its [methods].
|
||||
|
||||
In this menu definition, the first two entries are associated with a page, the last entry is not:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menus.main]]
|
||||
pageRef = '/about'
|
||||
weight = 10
|
||||
|
||||
[[menus.main]]
|
||||
pageRef = '/contact'
|
||||
weight = 20
|
||||
|
||||
[[menus.main]]
|
||||
name = 'Hugo'
|
||||
url = 'https://gohugo.io'
|
||||
weight = 30
|
||||
{{< /code-toggle >}}
|
||||
|
||||
In this example, if the menu entry is associated with a page, we use page's [`RelPermalink`] and [`LinkTitle`] when rendering the anchor element.
|
||||
|
||||
If the entry is not associated with a page, we use its `url` and `name` properties.
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Site.Menus.main }}
|
||||
{{ with .Page }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
|
||||
{{ else }}
|
||||
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
See the [menu templates] section for more information.
|
||||
|
||||
[`LinkTitle`]: /methods/page/linktitle
|
||||
[`RelPermalink`]: /methods/page/relpermalink
|
||||
[define menu entries]: /content-management/menus/
|
||||
[menu templates]: /templates/menu-templates/#page-references
|
||||
[methods]: /methods/page
|
Reference in New Issue
Block a user