diff --git a/docs/plugins/development/views.md b/docs/plugins/development/views.md index e3740de59..43cc0ce82 100644 --- a/docs/plugins/development/views.md +++ b/docs/plugins/development/views.md @@ -198,6 +198,7 @@ Plugins can inject custom content into certain areas of core NetBox views. This | Method | View | Description | |---------------------|-------------|-----------------------------------------------------| +| `head()` | All | Custom HTML `` block includes | | `navbar()` | All | Inject content inside the top navigation bar | | `list_buttons()` | List view | Add buttons to the top of the page | | `buttons()` | Object view | Add buttons to the top of the page | diff --git a/netbox/netbox/plugins/templates.py b/netbox/netbox/plugins/templates.py index 58f9ad80e..586391d4f 100644 --- a/netbox/netbox/plugins/templates.py +++ b/netbox/netbox/plugins/templates.py @@ -47,6 +47,13 @@ class PluginTemplateExtension: # Global methods # + def head(self): + """ + HTML returned by this method will be inserted in the page's `` block. This may be useful e.g. for + including additional Javascript or CSS resources. + """ + raise NotImplementedError + def navbar(self): """ Content that will be rendered inside the top navigation menu. Content should be returned as an HTML diff --git a/netbox/netbox/tests/dummy_plugin/template_content.py b/netbox/netbox/tests/dummy_plugin/template_content.py index e9a6b9da1..e962594d4 100644 --- a/netbox/netbox/tests/dummy_plugin/template_content.py +++ b/netbox/netbox/tests/dummy_plugin/template_content.py @@ -3,6 +3,9 @@ from netbox.plugins.templates import PluginTemplateExtension class GlobalContent(PluginTemplateExtension): + def head(self): + return "" + def navbar(self): return "GLOBAL CONTENT - NAVBAR" diff --git a/netbox/templates/base/base.html b/netbox/templates/base/base.html index 7ca2f575d..443562027 100644 --- a/netbox/templates/base/base.html +++ b/netbox/templates/base/base.html @@ -3,6 +3,7 @@ {% load helpers %} {% load i18n %} {% load django_htmx %} +{% load plugins %} content #} {% block head %}{% endblock %} + {% plugin_head %} diff --git a/netbox/utilities/templatetags/plugins.py b/netbox/utilities/templatetags/plugins.py index 16e65d697..40e6b8196 100644 --- a/netbox/utilities/templatetags/plugins.py +++ b/netbox/utilities/templatetags/plugins.py @@ -45,6 +45,14 @@ def _get_registered_content(obj, method, template_context): return mark_safe(html) +@register.simple_tag(takes_context=True) +def plugin_head(context): + """ + Render any content embedded by plugins + """ + return _get_registered_content(None, 'head', context) + + @register.simple_tag(takes_context=True) def plugin_navbar(context): """