Allow configuration templates to reference other templates #8886

Closed
opened 2025-12-29 20:42:30 +01:00 by adam · 2 comments
Owner

Originally created by @elipsion on GitHub (Nov 27, 2023).

NetBox version

v3.6.4

Feature type

Change to existing functionality

Proposed functionality

Amend the template loader (netbox/utilities/jinja2.py) to also fetch templates from the database, via some virtual path.

A suggested virtual path structure is to follow the /dev/disk/by-xxx model of udev, but the actual format is up to NetBox maintainers. It is probably best examplified:

  • /netbox/by-name/My generic template
  • /netbox/by-id/4

The risk of someone naming their templates as such in a Data Source is probably slim.

Use case

When writing configuration templates directly (i.e. not via Data Sources), I would like to reference other templates.

Database changes

None that I can think of.

External dependencies

No.

Considered alternatives

I tried to dig through the NetBox data model and render the template manually ({{ extras.ConfigTemplate.objects.get(name="Default").render() }}) but:

  1. This requires needlessly high knowledge of the data model for an average user.
  2. It's unclear how/if the configuration environment is passed along
  3. Only WebHook and JournalEntry are present in extras
Originally created by @elipsion on GitHub (Nov 27, 2023). ### NetBox version v3.6.4 ### Feature type Change to existing functionality ### Proposed functionality Amend the template loader (`netbox/utilities/jinja2.py`) to also fetch templates from the database, via some virtual path. A suggested virtual path structure is to follow the `/dev/disk/by-xxx` model of udev, but the actual format is up to NetBox maintainers. It is probably best examplified: - `/netbox/by-name/My generic template` - `/netbox/by-id/4` The risk of someone naming their templates as such in a Data Source is probably slim. ### Use case When writing configuration templates directly (i.e. not via Data Sources), I would like to reference other templates. ### Database changes None that I can think of. ### External dependencies No. ### Considered alternatives I tried to dig through the NetBox data model and render the template manually (`{{ extras.ConfigTemplate.objects.get(name="Default").render() }}`) but: 1. This requires needlessly high knowledge of the data model for an average user. 2. It's unclear how/if the configuration environment is passed along 3. Only `WebHook` and `JournalEntry` are present in `extras`
adam added the type: feature label 2025-12-29 20:42:30 +01:00
adam closed this issue 2025-12-29 20:42:30 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 26, 2024):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Feb 26, 2024): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@jeremystretch commented on GitHub (Mar 9, 2024):

It is already possible to reference other templates from within the same data source using the standard Jinja2 {% include %} tag. Please open a discussion if you need assistance utilizing this feature.

@jeremystretch commented on GitHub (Mar 9, 2024): It is already possible to reference other templates from within the same data source using the standard Jinja2 `{% include %}` tag. Please open a discussion if you need assistance utilizing this feature.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8886