From a74f15b908ba9364355f031f166c74ecadfea819 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Mon, 30 Oct 2023 15:57:32 +0800 Subject: [PATCH] feat(currentMenuItem.html): add template partial to retrieve the current menu item based on the current page URL The currentMenuItem.html template partial is added to the layouts/partials/function directory. This partial is used to retrieve the current menu item based on the current page URL. It iterates through the main menu items defined in the site configuration and compares the URL of each menu item with the URL of the current page. If a match is found, the name and ID of the menu item are stored in variables. Finally, a dictionary containing the name and ID is returned. This partial can be used to highlight the current menu item in the navigation menu. --- layouts/partials/function/currentMenuItem.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 layouts/partials/function/currentMenuItem.html diff --git a/layouts/partials/function/currentMenuItem.html b/layouts/partials/function/currentMenuItem.html new file mode 100644 index 0000000..d728f0d --- /dev/null +++ b/layouts/partials/function/currentMenuItem.html @@ -0,0 +1,15 @@ +{{- $currentPage := . -}} + +{{- $name := "" -}} +{{- $id := -1 -}} + +{{- range site.Menus.main -}} + {{ $menu_item_url := .URL | relLangURL }} + {{ $page_url:= $currentPage.RelPermalink | relLangURL }} + {{ if eq $menu_item_url $page_url }} + {{- $name = .Identifier -}} + {{- $id = .Weight -}} + {{- end -}} +{{- end -}} + +{{- return (dict "Name" $name "ID" $id) -}}