Add function to trim whitespaces in config templates #9196

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

Originally created by @heiko-ma on GitHub (Feb 6, 2024).

NetBox version

v3.7.1

Feature type

Change to existing functionality

Proposed functionality

When creating a config template, it would be useful if the jinja2 whitespace trimming feature (trim_blocks and lstrip_blocks) could be toggled on and off.
Currently, only manual trimming is available and it's a tedius task, especially with long config files.

Use case

We're currently implementing templates for our switch configs. To keep those templates somewhat readable and understandable (Jinja2 can be quite a mess sometimes) without needing to check every control clause for manual trimming, a switch to control this behavior would be really useful.

Database changes

No response

External dependencies

No response

Originally created by @heiko-ma on GitHub (Feb 6, 2024). ### NetBox version v3.7.1 ### Feature type Change to existing functionality ### Proposed functionality When creating a config template, it would be useful if the jinja2 whitespace trimming feature (trim_blocks and lstrip_blocks) could be toggled on and off. Currently, only manual trimming is available and it's a tedius task, especially with long config files. ### Use case We're currently implementing templates for our switch configs. To keep those templates somewhat readable and understandable (Jinja2 can be quite a mess sometimes) without needing to check every control clause for manual trimming, a switch to control this behavior would be really useful. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 20:46:50 +01:00
adam closed this issue 2025-12-29 20:46:50 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 6, 2024):

When creating a config template, it would be useful if the jinja2 whitespace trimming feature (trim_blocks and lstrip_blocks) could be toggled on and off.

This is achieved by passing the relevant Jinja2 environment parameters when creating the config template.

screenshot

@jeremystretch commented on GitHub (Feb 6, 2024): > When creating a config template, it would be useful if the jinja2 whitespace trimming feature (trim_blocks and lstrip_blocks) could be toggled on and off. This is achieved by passing the relevant [Jinja2 environment parameters](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Environment) when creating the config template. ![screenshot](https://github.com/netbox-community/netbox/assets/13487278/6714949d-aedf-4631-a3c3-5da207cd130a)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9196