Skip to content

Closes: #19793 - Nav menu link customization #19794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

bctiemann
Copy link
Contributor

@bctiemann bctiemann commented Jun 30, 2025

Closes: #19793

Changes the PluginMenuItem and PluginMenuButton classes to handle an alternate pre-rendered literal url init parameter, rather than just supporting link which must be a view name suitable for {% url %}.

This allows plugin authors to supply link target URLs that might require additional (arbitrary) kwargs for resolution, rather than relying on built-in NetBox view names.

Note that Django does not provide a supported way of passing arbitrary kwargs to {% url %}; the params must be known in advance and specified explicitly (i.e. {% url 'view_name' arg1='foo' arg2='bar' %}). This prevents us from implementing this functionality in a more elegant way, i.e. being able to pass a link_kwargs dict which could then be plugged into the template directly like {% url item.link **item.link_kwargs %}.

@bctiemann bctiemann changed the base branch from main to feature June 30, 2025 18:35
@bctiemann bctiemann requested review from a team and arthanson and removed request for a team June 30, 2025 18:41
@jeremystretch
Copy link
Member

I'm not convinced we need to (or should) support arbitrary executables in place of menu items. Where dynamic iteration is needed, a plugin author can pass an arbitrary object as items within a MenuGroup, and define its __iter__() method to return whatever MenuItems are prudent.

I tested this approach with the custom objects plugin and it works well. The only blocker I ran into there was the rigid requirement for passing a static view name as a MenuItem's link. Rather than introducing a separate, conflicting url parameter maybe it would make sense to introduce a link_kwargs argument that can be passed along with link for URL resolution in the menu item.

@bctiemann bctiemann changed the base branch from feature to main July 8, 2025 19:38
@bctiemann bctiemann requested a review from jeremystretch July 8, 2025 19:46
@bctiemann bctiemann changed the title Closes: #19793 - Nav menu callables Closes: #19793 - Nav menu link customization Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom link URLs for nav menu
2 participants