Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'

This commit is contained in:
Bjørn Erik Pedersen
2025-04-10 13:04:51 +02:00
987 changed files with 12379 additions and 14083 deletions

View File

@@ -3,11 +3,10 @@ title: Children
description: Returns a collection of child menu entries, if any, under the given menu entry.
categories: []
keywords: []
action:
related:
- methods/menu-entry/HasChildren
returnType: navigation.Menu
signatures: [MENUENTRY.Children]
params:
functions_and_methods:
returnType: navigation.Menu
signatures: [MENUENTRY.Children]
---
Use the `Children` method when rendering a nested menu.

View File

@@ -3,11 +3,10 @@ title: HasChildren
description: Reports whether the given menu entry has child menu entries.
categories: []
keywords: []
action:
related:
- methods/menu-entry/Children
returnType: bool
signatures: [MENUENTRY.HasChildren]
params:
functions_and_methods:
returnType: bool
signatures: [MENUENTRY.HasChildren]
---
Use the `HasChildren` method when rendering a nested menu.

View File

@@ -1,18 +1,16 @@
---
title: Identifier
description: Returns the `identifier` property of the given menu entry.
description: Returns the `identifier` property of the given menu entry.
categories: []
keywords: []
action:
related: []
returnType: string
signatures: [MENUENTRY.Identifier]
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.Identifier]
---
The `Identifier` method returns the `identifier` property of the menu entry. If you define the menu entry [automatically], it returns the page's section.
[automatically]: /content-management/menus/#define-automatically
{{< code-toggle file=hugo >}}
[[menus.main]]
identifier = 'about'
@@ -37,8 +35,7 @@ This example uses the `Identifier` method when querying the translation table on
</ul>
```
{{% note %}}
In the menu definition above, note that the `identifier` property is only required when two or more menu entries have the same name, or when localizing the name using translation tables.
> [!note]
> In the menu definition above, note that the `identifier` property is only required when two or more menu entries have the same name, or when localizing the name using translation tables.
[details]: /content-management/menus/#properties-front-matter
{{% /note %}}
[automatically]: /content-management/menus/#define-automatically

View File

@@ -1,12 +1,12 @@
---
title: KeyName
description: Returns the `identifier` property of the given menu entry, falling back to its `name` property.
description: Returns the `identifier` property of the given menu entry, falling back to its `name` property.
categories: []
keywords: []
action:
related: []
returnType: string
signatures: [MENUENTRY.KeyName]
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.KeyName]
---
In this menu definition, the second entry does not contain an `identifier`, so the `Identifier` method returns its `name` property instead:

View File

@@ -3,12 +3,10 @@ title: Menu
description: Returns the identifier of the menu that contains the given menu entry.
categories: []
keywords: []
action:
related:
- methods/page/IsMenuCurrent
- methods/page/HasMenuCurrent
returnType: string
signatures: [MENUENTRY.Menu]
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.Menu]
---
```go-html-template

View File

@@ -3,15 +3,15 @@ title: Name
description: Returns the `name` property of the given menu entry.
categories: []
keywords: []
action:
related: []
returnType: string
signatures: [MENUENTRY.Name]
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.Name]
---
If you define the menu entry [automatically], the `Name` method returns the page's [`LinkTitle`], falling back to its [`Title`].
If you define the menu entry [in front matter] or [in site configuration], the `Name` method returns the `name` property of the given menu entry. If the `name` is not defined, and the menu entry resolves to a page, the `Name` returns the page [`LinkTitle`], falling back to its [`Title`].
If you define the menu entry [in front matter] or [in site configuration], the `Name` method returns the `name` property of the given menu entry. If the `name` is not defined, and the menu entry resolves to a page, the `Name` returns the page [`LinkTitle`], falling back to its [`Title`].
[`LinkTitle`]: /methods/page/linktitle/
[`Title`]: /methods/page/title/

View File

@@ -3,10 +3,10 @@ title: Page
description: Returns the Page object associated with the given menu entry.
categories: []
keywords: []
action:
related: []
returnType: page.Page
signatures: [MENUENTRY.Page]
params:
functions_and_methods:
returnType: page.Page
signatures: [MENUENTRY.Page]
---
Regardless of how you [define menu entries], an entry associated with a page has access to its [methods].

View File

@@ -3,12 +3,10 @@ title: PageRef
description: Returns the `pageRef` property of the given menu entry.
categories: []
keywords: []
action:
related:
- /methods/menu-entry/URL
returnType: string
signatures: [MENUENTRY.PageRef]
toc: true
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.PageRef]
---
The use case for this method is rare.
@@ -31,28 +29,15 @@ If a matching page is not found:
- The [`Page`] method returns nil
- The [`HasMenuCurrent`] and [`IsMenuCurrent`] methods on a `Page` object return `false`
{{% note %}}
In almost also scenarios you should use the [`URL`] method instead.
[`URL`]: /methods/menu-entry/url/
{{% /note %}}
[defining a menu entry]: /content-management/menus/#define-in-site-configuration
[`Page`]: /methods/menu-entry/page/
[`URL`]: /methods/menu-entry/url/
[`IsMenuCurrent`]: /methods/page/ismenucurrent/
[`HasMenuCurrent`]: /methods/page/hasmenucurrent/
[`RelPermalink`]: /methods/page/relpermalink/
> [!note]
> In almost also scenarios you should use the [`URL`] method instead.
## Example
This example is contrived.
{{% note %}}
In almost also scenarios you should use the [`URL`] method instead.
[`URL`]: /methods/menu-entry/url/
{{% /note %}}
> [!note]
> In almost also scenarios you should use the [`URL`] method instead.
Consider this content structure:
@@ -77,13 +62,13 @@ weight = 20
With this template code:
{{< code file=layouts/partials/menu.html >}}
```go-html-template {file="layouts/partials/menu.html"}
<ul>
{{ range .Site.Menus.main }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
{{< /code >}}
```
Hugo render this HTML:
@@ -98,13 +83,13 @@ In the above note that the `href` attribute of the second `anchor` element is bl
With this template code:
{{< code file=layouts/partials/menu.html >}}
```go-html-template {file="layouts/partials/menu.html"}
<ul>
{{ range .Site.Menus.main }}
<li><a href="{{ or .URL .PageRef }}">{{ .Name }}</a></li>
{{ end }}
</ul>
{{< /code >}}
```
Hugo renders this HTML:
@@ -116,3 +101,9 @@ Hugo renders this HTML:
```
In the above note that Hugo populates the `href` attribute of the second `anchor` element with the `pageRef` property as defined in the site configuration because the template code falls back to the `PageRef` method.
[`HasMenuCurrent`]: /methods/page/hasmenucurrent/
[`IsMenuCurrent`]: /methods/page/ismenucurrent/
[`Page`]: /methods/menu-entry/page/
[`URL`]: /methods/menu-entry/url/
[defining a menu entry]: /content-management/menus/#define-in-site-configuration

View File

@@ -3,10 +3,10 @@ title: Params
description: Returns the `params` property of the given menu entry.
categories: []
keywords: []
action:
related: []
returnType: maps.Params
signatures: [MENUENTRY.Params]
params:
functions_and_methods:
returnType: maps.Params
signatures: [MENUENTRY.Params]
---
When you define menu entries [in site configuration] or [in front matter], you can include a `params` key to attach additional information to the entry. For example:

View File

@@ -3,10 +3,10 @@ title: Parent
description: Returns the `parent` property of the given menu entry.
categories: []
keywords: []
action:
related: []
returnType: string
signatures: [MENUENTRY.Parent]
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.Parent]
---
With this menu definition:
@@ -40,7 +40,7 @@ This template renders the nested menu, listing the `parent` property next each o
{{ if .HasChildren }}
<ul>
{{ range .Children }}
<li><a href="{{ .URL }}">{{ .Name }}</a> ({{ .Parent }})</li>
<li><a href="{{ .URL }}">{{ .Name }}</a> ({{ .Parent }})</li>
{{ end }}
</ul>
{{ end }}

View File

@@ -1,13 +1,12 @@
---
title: Post
description: Returns the `post` property of the given menu entry.
description: Returns the `post` property of the given menu entry.
categories: []
keywords: []
action:
related:
- methods/menu-entry/Pre
returnType: template.HTML
signatures: [MENUENTRY.Post]
params:
functions_and_methods:
returnType: template.HTML
signatures: [MENUENTRY.Post]
---
{{% include "methods/menu-entry/_common/pre-post.md" %}}
{{% include "/_common/menu-entries/pre-and-post.md" %}}

View File

@@ -1,13 +1,12 @@
---
title: Pre
description: Returns the `pre` property of the given menu entry.
description: Returns the `pre` property of the given menu entry.
categories: []
keywords: []
action:
related:
- methods/menu-entry/Post
returnType: template.HTML
signatures: [MENUENTRY.Pre]
params:
functions_and_methods:
returnType: template.HTML
signatures: [MENUENTRY.Pre]
---
{{% include "methods/menu-entry/_common/pre-post.md" %}}
{{% include "/_common/menu-entries/pre-and-post.md" %}}

View File

@@ -1,15 +1,15 @@
---
title: Title
description: Returns the `title` property of the given menu entry.
description: Returns the `title` property of the given menu entry.
categories: []
keywords: []
action:
related: []
returnType: string
signatures: [MENUENTRY.Title]
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.Title]
---
The `Title` method returns the `title` property of the given menu entry. If the `title` is not defined, and the menu entry resolves to a page, the `Title` returns the page [`Title`].
The `Title` method returns the `title` property of the given menu entry. If the `title` is not defined, and the menu entry resolves to a page, the `Title` returns the page [`Title`].
[`Title`]: /methods/page/title/

View File

@@ -3,10 +3,10 @@ title: URL
description: Returns the relative permalink of the page associated with the given menu entry, else its `url` property.
categories: []
keywords: []
action:
related: []
returnType: string
signatures: [MENUENTRY.URL]
params:
functions_and_methods:
returnType: string
signatures: [MENUENTRY.URL]
---
For menu entries associated with a page, the `URL` method returns the page's [`RelPermalink`], otherwise it returns the entry's `url` property.

View File

@@ -1,17 +1,17 @@
---
title: Weight
description: Returns the `weight` property of the given menu entry.
description: Returns the `weight` property of the given menu entry.
categories: []
keywords: []
action:
related: []
returnType: int
signatures: [MENUENTRY.Weight]
params:
functions_and_methods:
returnType: int
signatures: [MENUENTRY.Weight]
---
If you define the menu entry [automatically], the `Weight` method returns the pages [`Weight`].
If you define the menu entry [automatically], the `Weight` method returns the page's [`Weight`].
If you define the menu entry [in front matter] or [in site configuration], the `Weight` method returns the `weight` property, falling back to the pages `Weight`.
If you define the menu entry [in front matter] or [in site configuration], the `Weight` method returns the `weight` property, falling back to the page's `Weight`.
[`Weight`]: /methods/page/weight/
[automatically]: /content-management/menus/#define-automatically

View File

@@ -1,13 +0,0 @@
---
cascade:
_build:
list: never
publishResources: false
render: never
---
<!--
Files within this headless branch bundle are Markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
Include the rendered content using the "include" shortcode.
-->

View File

@@ -1,39 +0,0 @@
---
_comment: Do not remove front matter.
---
In this site configuration we enable rendering of [emoji shortcodes], and add emoji shortcodes before (pre) and after (post) each menu entry:
{{< code-toggle file=hugo >}}
enableEmoji = true
[[menus.main]]
name = 'About'
pageRef = '/about'
post = ':point_left:'
pre = ':point_right:'
weight = 10
[[menus.main]]
name = 'Contact'
pageRef = '/contact'
post = ':arrow_left:'
pre = ':arrow_right:'
weight = 20
{{< /code-toggle >}}
To render the menu:
```go-html-template
<ul>
{{ range .Site.Menus.main }}
<li>
{{ .Pre | markdownify }}
<a href="{{ .URL }}">{{ .Name }}</a>
{{ .Post | markdownify }}
</li>
{{ end }}
</ul>
```
[emoji shortcodes]: /quick-reference/emojis/

View File

@@ -4,9 +4,4 @@ linkTitle: Menu entry
description: Use these methods in your menu templates.
categories: []
keywords: []
menu:
docs:
parent: methods
---
Use these methods in your menu templates.