From c0b82df5fdf7e2994ba70973c70b5ba2e390db2f Mon Sep 17 00:00:00 2001 From: danilo-botelho <125575895+danilo-botelho@users.noreply.github.com> Date: Mon, 24 Mar 2025 17:59:05 -0300 Subject: [PATCH 1/2] feat: add a way to get selected Menu (not MenuItem) from context ref. #151 --- simple_menu/templatetags/simple_menu.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/simple_menu/templatetags/simple_menu.py b/simple_menu/templatetags/simple_menu.py index 598c5ae..74080d5 100644 --- a/simple_menu/templatetags/simple_menu.py +++ b/simple_menu/templatetags/simple_menu.py @@ -29,7 +29,9 @@ def find_selected(menu): return r return None + # Making it backward compatible (these should probably be renamed selected_menuitem and selected_menu, respectively) selected_menu = None + selected_menu_menu = None for name in menus: found_menu = find_selected(menus[name]) if found_menu: @@ -41,6 +43,7 @@ def find_selected(menu): selected_menu.selected = False selected_menu = found_menu + selected_menu_menu = menus[name] # now for the submenu submenu = [] @@ -56,6 +59,7 @@ def find_selected(menu): # set the items in our context context['menus'] = menus context['selected_menu'] = selected_menu + context['selected_menu_menu'] = selected_menu_menu context['submenu'] = submenu context['has_submenu'] = has_submenu From 84e1b5391b23639bb8f5842ba89895744a3b0493 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:04:06 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- simple_menu/templatetags/simple_menu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple_menu/templatetags/simple_menu.py b/simple_menu/templatetags/simple_menu.py index 74080d5..af860ca 100644 --- a/simple_menu/templatetags/simple_menu.py +++ b/simple_menu/templatetags/simple_menu.py @@ -31,7 +31,7 @@ def find_selected(menu): # Making it backward compatible (these should probably be renamed selected_menuitem and selected_menu, respectively) selected_menu = None - selected_menu_menu = None + selected_menu_menu = None for name in menus: found_menu = find_selected(menus[name]) if found_menu: