Add function to trim whitespaces in export templates via jinja environment settings #10309

Closed
opened 2025-12-29 21:29:46 +01:00 by adam · 1 comment
Owner

Originally created by @w1tht0uchp4d on GitHub (Oct 1, 2024).

Originally assigned to: @renatoalmeidaoliveira on GitHub.

NetBox version

3.7.5

Feature type

Change to existing functionality

Proposed functionality

The goal is to achieve feature parity between the [Provisioning --> Config Templates edit] and [Customization --> Export Templates dialog]. In config templates it is possible to use jinja environment parameters, in export templates it is not.
It's also the same behavior in Netbox v4.1.2 (checked via demo application).

Use case

I'm currently implementing a custom export template, which exports prefixes, their assigned VLANs and some custom fields. I'm aware that part of this, is also achievable via the csv export function, but I want to add some semantic sugar via the power of Jinja, like adding first host address, last host address, ...
The messy white space handling with jinja, unfortunately destroys the formatting of the csv.

Database changes

None required?

External dependencies

None?

Originally created by @w1tht0uchp4d on GitHub (Oct 1, 2024). Originally assigned to: @renatoalmeidaoliveira on GitHub. ### NetBox version 3.7.5 ### Feature type Change to existing functionality ### Proposed functionality The goal is to achieve feature parity between the [Provisioning --> Config Templates edit] and [Customization --> Export Templates dialog]. In config templates it is possible to use jinja environment parameters, in export templates it is not. It's also the same behavior in Netbox v4.1.2 (checked via demo application). ### Use case I'm currently implementing a custom export template, which exports prefixes, their assigned VLANs and some custom fields. I'm aware that part of this, is also achievable via the csv export function, but I want to add some semantic sugar via the power of Jinja, like adding first host address, last host address, ... The messy white space handling with jinja, unfortunately destroys the formatting of the csv. ### Database changes None required? ### External dependencies None?
adam added the status: acceptedtype: featurenetboxcomplexity: low labels 2025-12-29 21:29:46 +01:00
adam closed this issue 2025-12-29 21:29:47 +01:00
Author
Owner

@pl0xym0r commented on GitHub (Oct 7, 2024):

Both ConfigTemplate and ExportTemplate inherits from ExportTemplatesMixin

In ConfigTemplate there are params/methods like:
environment_params
def render()
def _get_environment()

Idk if it's too much for export templates but would it be great to move such params/functions to ExportTemplatesMixin ? Or modify utilities.jinja2.py ? At least, use the same enviroment creation for both cases.

@pl0xym0r commented on GitHub (Oct 7, 2024): Both ConfigTemplate and ExportTemplate inherits from ExportTemplatesMixin In ConfigTemplate there are params/methods like: environment_params def render() def _get_environment() Idk if it's too much for export templates but would it be great to move such params/functions to ExportTemplatesMixin ? Or modify utilities.jinja2.py ? At least, use the same enviroment creation for both cases.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10309