| 1 |
--- |
| 2 |
title: Configure menus |
| 3 |
linkTitle: Menus |
| 4 |
description: Centrally define menu entries for one or more menus. |
| 5 |
categories: [] |
| 6 |
keywords: [] |
| 7 |
--- |
| 8 |
|
| 9 |
> [!NOTE] |
| 10 |
> To understand Hugo's menu system, please refer to the [menus][] page. |
| 11 |
|
| 12 |
There are three ways to define menu entries: |
| 13 |
|
| 14 |
1. [Automatically][] |
| 15 |
1. In [front matter][] |
| 16 |
1. In your project configuration |
| 17 |
|
| 18 |
This page covers the project configuration method. |
| 19 |
|
| 20 |
## Example |
| 21 |
|
| 22 |
To define entries for a "main" menu: |
| 23 |
|
| 24 |
{{< code-toggle file=hugo >}} |
| 25 |
[[menus.main]] |
| 26 |
name = 'Home' |
| 27 |
pageRef = '/' |
| 28 |
weight = 10 |
| 29 |
|
| 30 |
[[menus.main]] |
| 31 |
name = 'Products' |
| 32 |
pageRef = '/products' |
| 33 |
weight = 20 |
| 34 |
|
| 35 |
[[menus.main]] |
| 36 |
name = 'Services' |
| 37 |
pageRef = '/services' |
| 38 |
weight = 30 |
| 39 |
{{< /code-toggle >}} |
| 40 |
|
| 41 |
This creates a menu structure that you can access with [`Menus`][] method on a `Site` object: |
| 42 |
|
| 43 |
```go-html-template |
| 44 |
{{ range .Site.Menus.main }} |
| 45 |
... |
| 46 |
{{ end }} |
| 47 |
``` |
| 48 |
|
| 49 |
See [menu templates][] for a detailed example. |
| 50 |
|
| 51 |
To define entries for a "footer" menu: |
| 52 |
|
| 53 |
{{< code-toggle file=hugo >}} |
| 54 |
[[menus.footer]] |
| 55 |
name = 'Terms' |
| 56 |
pageRef = '/terms' |
| 57 |
weight = 10 |
| 58 |
|
| 59 |
[[menus.footer]] |
| 60 |
name = 'Privacy' |
| 61 |
pageRef = '/privacy' |
| 62 |
weight = 20 |
| 63 |
{{< /code-toggle >}} |
| 64 |
|
| 65 |
Access this menu structure in the same way: |
| 66 |
|
| 67 |
```go-html-template |
| 68 |
{{ range .Site.Menus.footer }} |
| 69 |
... |
| 70 |
{{ end }} |
| 71 |
``` |
| 72 |
|
| 73 |
## Properties |
| 74 |
|
| 75 |
Menu entries usually include at least three properties: `name`, `weight`, and either `pageRef` or `url`. Use `pageRef` for internal page destinations and `url` for external destinations. |
| 76 |
|
| 77 |
These are the available menu entry properties: |
| 78 |
|
| 79 |
{{% include "/_common/menu-entry-properties.md" %}} |
| 80 |
|
| 81 |
`pageRef` |
| 82 |
: (`string`) The [logical path](g) of the target page. For example: |
| 83 |
|
| 84 |
page kind|pageRef |
| 85 |
:--|:-- |
| 86 |
home|`/` |
| 87 |
page|`/books/book-1` |
| 88 |
section|`/books` |
| 89 |
taxonomy|`/tags` |
| 90 |
term|`/tags/foo` |
| 91 |
|
| 92 |
`url` |
| 93 |
: (`string`) The destination URL. Use this for external destinations only. |
| 94 |
|
| 95 |
## Nested menu |
| 96 |
|
| 97 |
This nested menu demonstrates some of the available properties: |
| 98 |
|
| 99 |
<!-- markdownlint-disable MD033 --> |
| 100 |
{{< code-toggle file=hugo >}} |
| 101 |
[[menus.main]] |
| 102 |
name = 'Products' |
| 103 |
pageRef = '/products' |
| 104 |
weight = 10 |
| 105 |
|
| 106 |
[[menus.main]] |
| 107 |
name = 'Hardware' |
| 108 |
pageRef = '/products/hardware' |
| 109 |
parent = 'Products' |
| 110 |
weight = 1 |
| 111 |
|
| 112 |
[[menus.main]] |
| 113 |
name = 'Software' |
| 114 |
pageRef = '/products/software' |
| 115 |
parent = 'Products' |
| 116 |
weight = 2 |
| 117 |
|
| 118 |
[[menus.main]] |
| 119 |
name = 'Services' |
| 120 |
pageRef = '/services' |
| 121 |
weight = 20 |
| 122 |
|
| 123 |
[[menus.main]] |
| 124 |
name = 'Hugo' |
| 125 |
pre = '<i class="fa fa-heart"></i>' |
| 126 |
url = 'https://gohugo.io/' |
| 127 |
weight = 30 |
| 128 |
[menus.main.params] |
| 129 |
rel = 'external' |
| 130 |
{{< /code-toggle >}} |
| 131 |
<!-- markdownlint-enable MD033 --> |
| 132 |
|
| 133 |
[Automatically]: /content-management/menus/#define-automatically |
| 134 |
[`Menus`]: /methods/site/menus/ |
| 135 |
[front matter]: /content-management/menus/#define-in-front-matter |
| 136 |
[menu templates]: /templates/menu/ |
| 137 |
[menus]: /content-management/menus/ |