Modularization of HTML template components to simplify plugin construction #11543

Closed
opened 2025-12-29 21:46:36 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Aug 29, 2025).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v4.3.7

Feature type

New functionality

Proposed functionality

Introduce a set of Python class which can be utilities both in core NetBox and in plugins to render standardized data components within HTML templates. Proposed components include:

  • Attribute tables
  • Custom field tables
  • Related object counts
  • Related object lists
  • Markdown content

For example, an attribute table might defined like this:

site_details = AttributeTable({
    'Region': Attr(site.region, linkify=True),
    'Group': Attr(site.group, linkify=True),
    'Status': Badge(site.status, color=site.get_status_color()),
    'Tenant': Attr(site.tenant, nested=True),
    'Facility': Attr(site.facility),
}, title='Site')

When cast as a string within a template (e.g. {{ site_details }}), the AttributeTable instance will render the HTML necessary to construct a complete table element with the appropriate CSS styling applied. Similar approaches can be taken for the other proposed components.

Use case

Currently, HTML templates used to display individual objects generally employ a base template (i.e. generic/object.html) which is extended with arbitrary HTML to display the desired content. The resulting templates, while fully functional, are subject to drift as the structuring and styling of the NetBox UI evolves over time. It can also be quite tedious to build out these components using raw HTML; a class-based approach greatly simplifies and speeds up the process.

Database changes

N/A

External dependencies

N/A

Originally created by @jeremystretch on GitHub (Aug 29, 2025). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v4.3.7 ### Feature type New functionality ### Proposed functionality Introduce a set of Python class which can be utilities both in core NetBox and in plugins to render standardized data components within HTML templates. Proposed components include: - Attribute tables - Custom field tables - Related object counts - Related object lists - Markdown content For example, an attribute table might defined like this: ```python site_details = AttributeTable({ 'Region': Attr(site.region, linkify=True), 'Group': Attr(site.group, linkify=True), 'Status': Badge(site.status, color=site.get_status_color()), 'Tenant': Attr(site.tenant, nested=True), 'Facility': Attr(site.facility), }, title='Site') ``` When cast as a string within a template (e.g. `{{ site_details }}`), the AttributeTable instance will render the HTML necessary to construct a complete table element with the appropriate CSS styling applied. Similar approaches can be taken for the other proposed components. ### Use case Currently, HTML templates used to display individual objects generally employ a base template (i.e. `generic/object.html`) which is extended with arbitrary HTML to display the desired content. The resulting templates, while fully functional, are subject to drift as the structuring and styling of the NetBox UI evolves over time. It can also be quite tedious to build out these components using raw HTML; a class-based approach greatly simplifies and speeds up the process. ### Database changes N/A ### External dependencies N/A
adam added the status: acceptedtype: featuretopic: pluginsnetboxcomplexity: high labels 2025-12-29 21:46:36 +01:00
adam closed this issue 2025-12-29 21:46:36 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11543