mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
Use canonical key when documenting menu configs
This commit is contained in:
@@ -48,7 +48,7 @@ To add a page to the "main" menu:
|
||||
|
||||
{{< code-toggle file=content/about.md fm=true >}}
|
||||
title = 'About'
|
||||
menu = 'main'
|
||||
menus = 'main'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Access the entry with `site.Menus.main` in your templates. See [menu templates] for details.
|
||||
@@ -57,11 +57,15 @@ To add a page to the "main" and "footer" menus:
|
||||
|
||||
{{< code-toggle file=content/contact.md fm=true >}}
|
||||
title = 'Contact'
|
||||
menu = ['main','footer']
|
||||
menus = ['main','footer']
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Access the entry with `site.Menus.main` and `site.Menus.footer` in your templates. See [menu templates] for details.
|
||||
|
||||
{{% note %}}
|
||||
The configuration key in the examples above is `menus`. The `menu` (singular) configuration key is an alias for `menus`.
|
||||
{{% /note %}}
|
||||
|
||||
### Properties {#properties-front-matter}
|
||||
|
||||
Use these properties when defining menu entries in front matter:
|
||||
@@ -96,11 +100,11 @@ This front matter menu entry demonstrates some of the available properties:
|
||||
|
||||
{{< code-toggle file=content/products/software.md fm=true >}}
|
||||
title = 'Software'
|
||||
[menu.main]
|
||||
[[menus.main]]
|
||||
parent = 'Products'
|
||||
weight = 20
|
||||
pre = '<i class="fa-solid fa-code"></i>'
|
||||
[menu.main.params]
|
||||
[menus.main.params]
|
||||
class = 'center'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
@@ -111,17 +115,17 @@ Access the entry with `site.Menus.main` in your templates. See [menu templates]
|
||||
To define entries for the "main" menu:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Home'
|
||||
pageRef = '/'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/products'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
weight = 30
|
||||
@@ -132,12 +136,12 @@ This creates a menu structure that you can access with `site.Menus.main` in your
|
||||
To define entries for the "footer" menu:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.footer]]
|
||||
[[menus.footer]]
|
||||
name = 'Terms'
|
||||
pageRef = '/terms'
|
||||
weight = 10
|
||||
|
||||
[[menu.footer]]
|
||||
[[menus.footer]]
|
||||
name = 'Privacy'
|
||||
pageRef = '/privacy'
|
||||
weight = 20
|
||||
@@ -145,6 +149,10 @@ weight = 20
|
||||
|
||||
This creates a menu structure that you can access with `site.Menus.footer` in your templates. See [menu templates] for details.
|
||||
|
||||
{{% note %}}
|
||||
The configuration key in the examples above is `menus`. The `menu` (singular) configuration key is an alias for `menus`.
|
||||
{{% /note %}}
|
||||
|
||||
### Properties {#properties-site-configuration}
|
||||
|
||||
{{% note %}}
|
||||
@@ -177,34 +185,34 @@ url
|
||||
This nested menu demonstrates some of the available properties:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/products'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Hardware'
|
||||
pageRef = '/products/hardware'
|
||||
parent = 'Products'
|
||||
weight = 1
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Software'
|
||||
pageRef = '/products/software'
|
||||
parent = 'Products'
|
||||
weight = 2
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Hugo'
|
||||
pre = '<i class="fa fa-heart"></i>'
|
||||
url = 'https://gohugo.io/'
|
||||
weight = 30
|
||||
[menu.main.params]
|
||||
[menus.main.params]
|
||||
rel = 'external'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
|
||||
@@ -546,12 +546,12 @@ languageCode = 'de-DE'
|
||||
languageName = 'Deutsch'
|
||||
weight = 1
|
||||
|
||||
[[languages.de.menu.main]]
|
||||
[[languages.de.menus.main]]
|
||||
name = 'Produkte'
|
||||
pageRef = '/products'
|
||||
weight = 10
|
||||
|
||||
[[languages.de.menu.main]]
|
||||
[[languages.de.menus.main]]
|
||||
name = 'Leistungen'
|
||||
pageRef = '/services'
|
||||
weight = 20
|
||||
@@ -561,12 +561,12 @@ languageCode = 'en-US'
|
||||
languageName = 'English'
|
||||
weight = 2
|
||||
|
||||
[[languages.en.menu.main]]
|
||||
[[languages.en.menus.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/products'
|
||||
weight = 10
|
||||
|
||||
[[languages.en.menu.main]]
|
||||
[[languages.en.menus.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
weight = 20
|
||||
@@ -579,13 +579,12 @@ With a more complex menu structure, create a [configuration directory] and split
|
||||
```text
|
||||
config/
|
||||
└── _default/
|
||||
├── menus/
|
||||
│ ├── menu.de.toml
|
||||
│ └── menu.en.toml
|
||||
├── menus.de.toml
|
||||
├── menus.en.toml
|
||||
└── hugo.toml
|
||||
```
|
||||
|
||||
{{< code-toggle file=config/_default/menus/menu.de >}}
|
||||
{{< code-toggle file=config/_default/menus.de >}}
|
||||
[[main]]
|
||||
name = 'Produkte'
|
||||
pageRef = '/products'
|
||||
@@ -596,7 +595,7 @@ pageRef = '/services'
|
||||
weight = 20
|
||||
{{< /code-toggle >}}
|
||||
|
||||
{{< code-toggle file=config/_default/menus/menu.en >}}
|
||||
{{< code-toggle file=config/_default/menus.en >}}
|
||||
[[main]]
|
||||
name = 'Products'
|
||||
pageRef = '/products'
|
||||
@@ -627,12 +626,12 @@ The `identifier` depends on how you define menu entries:
|
||||
For example, if you define menu entries in site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'products'
|
||||
name = 'Products'
|
||||
pageRef = '/products'
|
||||
weight = 10
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'services'
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
|
||||
@@ -19,7 +19,7 @@ aliases: [/functions/safehtmlattr]
|
||||
Given a site configuration that contains this menu entry:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = "IRC"
|
||||
url = "irc://irc.freenode.net/#golang"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
@@ -23,7 +23,7 @@ Without `safeURL`, only the URI schemes `http:`, `https:` and `mailto:` are cons
|
||||
The following examples use a [site `hugo.toml`][configuration] with the following [menu entry][menus]:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = "IRC: #golang at freenode"
|
||||
url = "irc://irc.freenode.net/#golang"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
@@ -15,18 +15,18 @@ Use the `Children` method when rendering a nested menu.
|
||||
With this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/product'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Product 1'
|
||||
pageRef = '/products/product-1'
|
||||
parent = 'Products'
|
||||
weight = 1
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Product 2'
|
||||
pageRef = '/products/product-2'
|
||||
parent = 'Products'
|
||||
|
||||
@@ -15,18 +15,18 @@ Use the `HasChildren` method when rendering a nested menu.
|
||||
With this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/product'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Product 1'
|
||||
pageRef = '/products/product-1'
|
||||
parent = 'Products'
|
||||
weight = 1
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Product 2'
|
||||
pageRef = '/products/product-2'
|
||||
parent = 'Products'
|
||||
|
||||
@@ -14,13 +14,13 @@ The `Identifier` method returns the `identifier` property of the menu entry. If
|
||||
[automatically]: /content-management/menus/#define-automatically
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'about'
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'contact'
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
|
||||
@@ -12,13 +12,13 @@ action:
|
||||
In this menu definition, the second entry does not contain an `identifier`, so the `Identifier` method returns its `name` property instead:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'about'
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
weight = 20
|
||||
|
||||
@@ -14,15 +14,15 @@ Regardless of how you [define menu entries], an entry associated with a page has
|
||||
In this menu definition, the first two entries are associated with a page, the last entry is not:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
pageRef = '/about'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
pageRef = '/contact'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Hugo'
|
||||
url = 'https://gohugo.io'
|
||||
weight = 30
|
||||
|
||||
@@ -12,21 +12,21 @@ action:
|
||||
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:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Hugo'
|
||||
url = 'https://gohugo.io'
|
||||
weight = 30
|
||||
[menu.main.params]
|
||||
[menus.main.params]
|
||||
rel = 'external'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
|
||||
@@ -12,19 +12,18 @@ action:
|
||||
With this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[menu]
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/product'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Product 1'
|
||||
pageRef = '/products/product-1'
|
||||
parent = 'Products'
|
||||
weight = 1
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Product 2'
|
||||
pageRef = '/products/product-2'
|
||||
parent = 'Products'
|
||||
|
||||
@@ -7,14 +7,14 @@ In this site configuration we enable rendering of [emoji shortcodes], and add em
|
||||
{{< code-toggle file=hugo >}}
|
||||
enableEmoji = true
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
post = ':point_left:'
|
||||
pre = ':point_right:'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
post = ':arrow_left:'
|
||||
|
||||
@@ -14,17 +14,17 @@ The `Sort` method returns the given menu with its entries sorted by `name`.
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
weight = 30
|
||||
|
||||
@@ -16,19 +16,19 @@ The `ByWeight` method returns the given menu with its entries sorted by [`weight
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'about'
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'services'
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
identifier = 'contact'
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
|
||||
@@ -14,17 +14,17 @@ The `Limit` method returns the given menu, limited to the first N entries.
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
weight = 30
|
||||
|
||||
@@ -14,17 +14,17 @@ The `Reverse` method returns the given menu, reversing the sort order of its ent
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
weight = 30
|
||||
|
||||
@@ -22,27 +22,27 @@ Menus can be defined and localized in several ways. Please see the [menus] secti
|
||||
A site can have multiple menus. For example, a main menu and a footer menu:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Home'
|
||||
pageRef = '/'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Books'
|
||||
pageRef = '/books'
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
[[menus.main]]
|
||||
name = 'Films'
|
||||
pageRef = '/films'
|
||||
weight = 30
|
||||
|
||||
[[menu.footer]]
|
||||
[[menus.footer]]
|
||||
name = 'Legal'
|
||||
pageRef = '/legal'
|
||||
weight = 10
|
||||
|
||||
[[menu.footer]]
|
||||
[[menus.footer]]
|
||||
name = 'Privacy'
|
||||
pageRef = '/privacy'
|
||||
weight = 20
|
||||
|
||||
Reference in New Issue
Block a user