diff --git a/content/en/content-management/menus.md b/content/en/content-management/menus.md index c2eadf50f..4278b03be 100644 --- a/content/en/content-management/menus.md +++ b/content/en/content-management/menus.md @@ -36,47 +36,7 @@ A **menu** is a named array of menu entries accessible by name via the [`.Site.M If you make use of the [multilingual feature](/content-management/multilingual/), you can define language-independent menus. {{% /note %}} -A menu entry has the following properties (i.e., variables) available to it: - -`.URL` -: string - -`.Name` -: string - -`.Menu` -: string - -`.Identifier` -: string - -`.Pre` -: template.HTML - -`.Post` -: template.HTML - -`.Weight` -: int - -`.Parent` -: string - -`.Children` -: Menu - -Note that menus also have the following functions available as well: - -`.HasChildren` -: boolean - -Additionally, there are some relevant functions available to menus on a page: - -`.IsMenuCurrent` -: (menu string, menuEntry *MenuEntry ) boolean - -`.HasMenuCurrent` -: (menu string, menuEntry *MenuEntry) boolean +See the [Menu Entry Properties][me-props] for all the variables and functions related to a menu entry. ## Add content to menus @@ -139,7 +99,7 @@ The URLs must be relative to the context root. If the `baseURL` is `https://exam {{% /note %}} ## Nesting - + All nesting of content is done via the `parent` field. The parent of an entry should be the identifier of another entry. The identifier should be unique (within a menu). @@ -159,3 +119,4 @@ See [Menu Templates](/templates/menu-templates/) for information on how to rende [config]: /getting-started/configuration/ [multilingual]: /content-management/multilingual/ [sitevars]: /variables/ +[me-props]: /variables/menus/ diff --git a/content/en/functions/hasmenucurrent.md b/content/en/functions/hasmenucurrent.md index eac41103e..c7b8eb7a9 100644 --- a/content/en/functions/hasmenucurrent.md +++ b/content/en/functions/hasmenucurrent.md @@ -10,14 +10,18 @@ menu: docs: parent: "functions" keywords: [menus] -signature: ["HasMenuCurrent"] +signature: ["PAGE.HasMenuCurrent MENU MENUENTRY"] workson: [menus] hugoversion: -relatedfuncs: [] +relatedfuncs: ["IsMenuCurrent"] deprecated: false toc: false -draft: true +draft: false aliases: [] --- -Used in [menu templates](/templates/menu-templates/). +`.HasMenuCurrent` is a method in `Page` object returning a _boolean_ value. It +returns `true` if the PAGE is the same object as the `.Page` in one of the +**children menu entries** under MENUENTRY in a given MENU. + +You can find its example use in [menu templates](/templates/menu-templates/). diff --git a/content/en/functions/ismenucurrent.md b/content/en/functions/ismenucurrent.md index 647dcdcf0..66c7197a2 100644 --- a/content/en/functions/ismenucurrent.md +++ b/content/en/functions/ismenucurrent.md @@ -10,14 +10,18 @@ menu: docs: parent: "functions" keywords: [menus] -signature: ["IsMenuCurrent"] +signature: ["PAGE.IsMenuCurrent MENU MENUENTRY"] workson: [menus] hugoversion: -relatedfuncs: [] +relatedfuncs: ["HasMenuCurrent"] deprecated: false -draft: true +draft: false aliases: [] needsexample: true --- -Used in [menu templates](/templates/menu-templates/). +`.IsMenuCurrent` is a method in `Page` object returning a _boolean_ value. It +returns `true` if the PAGE is the same object as the `.Page` in MENUENTRY in a +given MENU. + +You can find its example use in [menu templates](/templates/menu-templates/). diff --git a/content/en/readfiles/menuvars.md b/content/en/readfiles/menuvars.md deleted file mode 100644 index 339fc108d..000000000 --- a/content/en/readfiles/menuvars.md +++ /dev/null @@ -1,39 +0,0 @@ -`.URL` -: string - -`.Name` -: string - -`.Menu` -: string - -`.Identifier` -: string - -`.Pre` -: template.HTML - -`.Post` -: template.HTML - -`.Weight` -: int - -`.Parent` -: string - -`.Children` -: Menu - -Note that menus also have the following functions available as well: - -[`.HasChildren`](/functions/haschildren/) -: boolean - -Additionally, there are some relevant functions available to menus on a page: - -[`.IsMenuCurrent`](/functions/ismenucurrent/) -: (menu string, menuEntry *MenuEntry ) boolean - -[`.HasMenuCurrent`](/functions/hasmenucurrent/) -: (menu string, menuEntry *MenuEntry) boolean \ No newline at end of file diff --git a/content/en/variables/menus.md b/content/en/variables/menus.md index 4216d9763..69d46ca2b 100644 --- a/content/en/variables/menus.md +++ b/content/en/variables/menus.md @@ -1,7 +1,7 @@ --- -title: Menu Variables -linktitle: Menu Variables -description: A menu entry in a menu template has specific variables and functions to make menu management easier. +title: Menu Entry Properties +linktitle: Menu Entry Properties +description: A menu entry in a menu-template has specific variables and functions to make menu management easier. date: 2017-03-12 publishdate: 2017-03-12 lastmod: 2017-03-12 @@ -19,49 +19,106 @@ aliases: [/variables/menu/] toc: false --- -The [menu template][] has the following properties: - -.URL -: string - -.Name -: string - -.Title -: string - -This is a link title, meant to be used in `title`-Attributes of the menu's ``-tags. -By default it returns `.Page.LinkTitle`, as long as the menu entry was created -through the page's front matter and not through the site config. -Setting it explicitly in the site config or the page's front matter overrides this behaviour. - -.Page -: [Page Object](/variables/page/) - -The `.Page` variable holds a reference to the page. -It's only set when the menu entry is created from the page's front matter, -not when it's created from the site config. +A **menu entry** has the following properties available that can be used in a +[menu template][menu-template]. +## Menu Entry Variables .Menu -: string +: _string_
+Name of the **menu** that contains this **menu entry**. + +.URL +: _string_
+URL that the menu entry points to. The `url` key, if set for the menu entry, +sets this value. If that key is not set, and if the menu entry is set in a page +front-matter, this value defaults to the page's `.RelPermalink`. + +.Page +: _\*Page_
+Reference to the [page object][page-object] associated with the menu entry. This +will be non-nil if the menu entry is set via a page's front-matter and not via +the site config. + +.Name +: _string_
+Name of the menu entry. The `name` key, if set for the menu entry, sets +this value. If that key is not set, and if the menu entry is set in a page +front-matter, this value defaults to the page's `.LinkTitle`. .Identifier -: string +: _string_
+Value of the `identifier` key if set for the menu entry. This value must be +unique for each menu entry. **It is necessary to set a unique identifier +manually if two or more menu entries have the same `.Name`.** .Pre -: template.HTML +: _template.HTML_
+Value of the `pre` key if set for the menu entry. This value typically contains +a string representing HTML. .Post -: template.HTML +: _template.HTML_
+Value of the `post` key if set for the menu entry. This value typically contains +a string representing HTML. .Weight -: int +: _int_
+Value of the `weight` key if set for the menu entry. If that key is not set, +and if the menu entry is set in a page front-matter, this value defaults to the +page's `.Weight`. .Parent -: string +: _string_
+Name (or Identifier if present) of this menu entry's parent **menu entry**. The +`parent` key, if set for the menu entry, sets this value. If this key is set, +this menu entry nests under that parent entry, else it nests directly under the +`.Menu`. .Children -: Menu +: _Menu_
+This value is auto-populated by Hugo. It is a collection of children menu +entries, if any, under the current menu entry. -[menu template]: /templates/menu-templates/ +## Menu Entry Functions + +Menus also have the following functions available: + +[.HasChildren](/functions/haschildren/) +: _boolean_
+Returns `true` if `.Children` is non-nil. + +.KeyName +: _string_
+Returns the `.Identifier` if present, else returns the `.Name`. + +.IsEqual +: _boolean_
+Returns `true` if the two compared menu entries represent the same menu entry. + +.IsSameResource +: _boolean_
+Returns `true` if the two compared menu entries have the same `.URL`. + +.Title +: _string_
+Link title, meant to be used in the `title` attribute of a menu entry's +`
`-tags. Returns the menu entry's `title` key if set. Else, if the menu +entry was created through a page's front-matter, it returns the page's +`.LinkTitle`. Else, it just returns an empty string. + +## Other Menu-related Functions + +Additionally, here are some relevant methods available to menus on a page: + +.IsMenuCurrent +: _(menu string, menuEntry *MenuEntry ) boolean_
+See [`.IsMenuCurrent` method](/functions/ismenucurrent/). + +.HasMenuCurrent +: _(menu string, menuEntry *MenuEntry) boolean_
+See [`.HasMenuCurrent` method](/functions/hasmenucurrent/). + + +[menu-template]: /templates/menu-templates/ +[page-object]: /variables/page/