From 1ada5d47e0485d708ae6416424f309db679c43ae Mon Sep 17 00:00:00 2001 From: David Jones Date: Sun, 22 Nov 2020 13:09:59 -0800 Subject: [PATCH] Add menu params Fixes #7951 --- content/en/content-management/menus.md | 18 ++++++++++++++++++ content/en/templates/menu-templates.md | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/content/en/content-management/menus.md b/content/en/content-management/menus.md index 9ac6f8bff..6b89c44da 100644 --- a/content/en/content-management/menus.md +++ b/content/en/content-management/menus.md @@ -113,6 +113,24 @@ This means that `.Title` will be used unless `.LinkTitle` is present, etc. In pr 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. +## Params + +You can also add user-defined content to menu items via the `params` field. + +A common use case is to define a custom param to add a css class to a specific menu item. + +{{< code-toggle file="config" >}} +[[menu.main]] + name = "about hugo" + pre = "" + weight = -110 + identifier = "about" + url = "/about/" + [menu.main.params] + class = "highlight-menu-item" +{{}} + + ## Render Menus See [Menu Templates](/templates/menu-templates/) for information on how to render your site menus within your templates. diff --git a/content/en/templates/menu-templates.md b/content/en/templates/menu-templates.md index b39fe42a9..8893d7b5a 100644 --- a/content/en/templates/menu-templates.md +++ b/content/en/templates/menu-templates.md @@ -160,3 +160,23 @@ Here's an example: {{ end }} ``` + +## Using .Params in Menus + +User-defined content on menu items are accessible via `.Params`. + +Here's an example: + +``` + +``` + +{{% note %}} +With Menu-level .Params they can easily exist on one menu item but not another. It's recommended to access them gracefully using the [with function](/functions/with). +{{% /note %}} \ No newline at end of file