menus.md (4051B)
1 --- 2 title: Menu Entry Properties 3 linktitle: Menu Entry Properties 4 description: A menu entry in a menu-template has specific variables and functions to make menu management easier. 5 date: 2017-03-12 6 publishdate: 2017-03-12 7 lastmod: 2017-03-12 8 categories: [variables and params] 9 keywords: [menus] 10 draft: false 11 menu: 12 docs: 13 title: "variables defined by a menu entry" 14 parent: "variables" 15 weight: 50 16 weight: 50 17 sections_weight: 50 18 aliases: [/variables/menu/] 19 toc: false 20 --- 21 22 A **menu entry** has the following properties available that can be used in a 23 [menu template][menu-template]. 24 25 ## Menu Entry Variables 26 27 .Menu 28 : _string_ <br /> 29 Name of the **menu** that contains this **menu entry**. 30 31 .URL 32 : _string_ <br /> 33 URL that the menu entry points to. The `url` key, if set for the menu entry, 34 sets this value. If that key is not set, and if the menu entry is set in a page 35 front-matter, this value defaults to the page's `.RelPermalink`. 36 37 .Page 38 : _\*Page_ <br /> 39 Reference to the [page object][page-object] associated with the menu entry. This 40 will be non-nil if the menu entry is set via a page's front-matter and not via 41 the site config. 42 43 .PageRef {{< new-in "0.86.0" >}} 44 : _string_ <br /> Can be set if defined in site config and the menu entry refers to a Page. [site.GetPage](/functions/getpage/) will be used to do the page lookup. If this is set, you don't need to set the `URL`. 45 46 .Name 47 : _string_ <br /> 48 Name of the menu entry. The `name` key, if set for the menu entry, sets 49 this value. If that key is not set, and if the menu entry is set in a page 50 front-matter, this value defaults to the page's `.LinkTitle`. 51 52 .Identifier 53 : _string_ <br /> 54 Value of the `identifier` key if set for the menu entry. This value must be 55 unique for each menu entry. **It is necessary to set a unique identifier 56 manually if two or more menu entries have the same `.Name`.** 57 58 .Pre 59 : _template.HTML_ <br /> 60 Value of the `pre` key if set for the menu entry. This value typically contains 61 a string representing HTML. 62 63 .Post 64 : _template.HTML_ <br /> 65 Value of the `post` key if set for the menu entry. This value typically contains 66 a string representing HTML. 67 68 .Weight 69 : _int_ <br /> 70 Value of the `weight` key if set for the menu entry. By default the entries in 71 a menu are sorted ascending by their `weight`. If that key is not set, and if 72 the menu entry is set in a page front-matter, this value defaults to the page's 73 `.Weight`. 74 75 .Parent 76 : _string_ <br /> 77 Name (or Identifier if present) of this menu entry's parent **menu entry**. The 78 `parent` key, if set for the menu entry, sets this value. If this key is set, 79 this menu entry nests under that parent entry, else it nests directly under the 80 `.Menu`. 81 82 .Children 83 : _Menu_ <br /> 84 This value is auto-populated by Hugo. It is a collection of children menu 85 entries, if any, under the current menu entry. 86 87 ## Menu Entry Functions 88 89 Menus also have the following functions available: 90 91 .HasChildren 92 : _boolean_ <br /> 93 Returns `true` if `.Children` is non-nil. 94 95 .KeyName 96 : _string_ <br /> 97 Returns the `.Identifier` if present, else returns the `.Name`. 98 99 .IsEqual 100 : _boolean_ <br /> 101 Returns `true` if the two compared menu entries represent the same menu entry. 102 103 .IsSameResource 104 : _boolean_ <br /> 105 Returns `true` if the two compared menu entries have the same `.URL`. 106 107 .Title 108 : _string_ <br /> 109 Link title, meant to be used in the `title` attribute of a menu entry's 110 `<a>`-tags. Returns the menu entry's `title` key if set. Else, if the menu 111 entry was created through a page's front-matter, it returns the page's 112 `.LinkTitle`. Else, it just returns an empty string. 113 114 ## Other Menu-related Functions 115 116 Additionally, here are some relevant methods available to menus on a page: 117 118 .IsMenuCurrent 119 : _(menu string, menuEntry *MenuEntry ) boolean_ <br /> 120 See [`.IsMenuCurrent` method](/functions/ismenucurrent/). 121 122 .HasMenuCurrent 123 : _(menu string, menuEntry *MenuEntry) boolean_ <br /> 124 See [`.HasMenuCurrent` method](/functions/hasmenucurrent/). 125 126 127 [menu-template]: /templates/menu-templates/ 128 [page-object]: /variables/page/