github.com/rabbouni145/gg@v0.47.1/docs/content/en/content-management/menus.md (about) 1 --- 2 title: Menus 3 linktitle: Menus 4 description: Hugo has a simple yet powerful menu system. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-03-31 8 categories: [content management] 9 keywords: [menus] 10 draft: false 11 menu: 12 docs: 13 parent: "content-management" 14 weight: 120 15 weight: 120 #rem 16 aliases: [/extras/menus/] 17 toc: true 18 --- 19 20 {{% note "Lazy Blogger"%}} 21 If all you want is a simple menu for your sections, see the ["Section Menu for Lazy Bloggers" in Menu Templates](/templates/menu-templates/#section-menu-for-lazy-bloggers). 22 {{% /note %}} 23 24 You can do this: 25 26 * Place content in one or many menus 27 * Handle nested menus with unlimited depth 28 * Create menu entries without being attached to any content 29 * Distinguish active element (and active branch) 30 31 ## What is a Menu in Hugo? 32 33 A **menu** is a named array of menu entries accessible by name via the [`.Site.Menus` site variable][sitevars]. For example, you can access your site's `main` menu via `.Site.Menus.main`. 34 35 {{% note "Menus on Multilingual Sites" %}} 36 If you make use of the [multilingual feature](/content-management/multilingual/), you can define language-independent menus. 37 {{% /note %}} 38 39 See the [Menu Entry Properties][me-props] for all the variables and functions related to a menu entry. 40 41 ## Add content to menus 42 43 Hugo allows you to add content to a menu via the content's [front matter](/content-management/front-matter/). 44 45 ### Simple 46 47 If all you need to do is add an entry to a menu, the simple form works well. 48 49 #### A Single Menu 50 51 ``` 52 --- 53 menu: "main" 54 --- 55 ``` 56 57 #### Multiple Menus 58 59 ``` 60 --- 61 menu: ["main", "footer"] 62 --- 63 ``` 64 65 #### Advanced 66 67 68 ``` 69 --- 70 menu: 71 docs: 72 parent: 'extras' 73 weight: 20 74 --- 75 ``` 76 77 ## Add Non-content Entries to a Menu 78 79 You can also add entries to menus that aren’t attached to a piece of content. This takes place in your Hugo project's [`config` file][config]. 80 81 Here’s an example snippet pulled from a configuration file: 82 83 {{< code-toggle file="config.toml" >}} 84 [[menu.main]] 85 name = "about hugo" 86 pre = "<i class='fa fa-heart'></i>" 87 weight = -110 88 identifier = "about" 89 url = "/about/" 90 [[menu.main]] 91 name = "getting started" 92 pre = "<i class='fa fa-road'></i>" 93 weight = -100 94 url = "/getting-started/" 95 {{< /code-toggle >}} 96 97 {{% note %}} 98 The URLs must be relative to the context root. If the `baseURL` is `https://example.com/mysite/`, then the URLs in the menu must not include the context root `mysite`. Using an absolute URL will override the baseURL. If the value used for `URL` in the above example is `https://subdomain.example.com/`, the output will be `https://subdomain.example.com`. 99 {{% /note %}} 100 101 ## Nesting 102 103 All nesting of content is done via the `parent` field. 104 105 The parent of an entry should be the identifier of another entry. The identifier should be unique (within a menu). 106 107 The following order is used to determine an Identifier: 108 109 `.Name > .LinkTitle > .Title` 110 111 This means that `.Title` will be used unless `.LinkTitle` is present, etc. In practice, `.Name` and `.Identifier` are only used to structure relationships and therefore never displayed. 112 113 In this example, the top level of the menu is defined in your [site `config` file][config]). All content entries are attached to one of these entries via the `.Parent` field. 114 115 ## Render Menus 116 117 See [Menu Templates](/templates/menu-templates/) for information on how to render your site menus within your templates. 118 119 [config]: /getting-started/configuration/ 120 [multilingual]: /content-management/multilingual/ 121 [sitevars]: /variables/ 122 [me-props]: /variables/menus/