Page MenuHomeVyOS Platform

Controlling whitespace in Jinja templates (template cleanup parent task)
Resolved (N/A)Public

Description

While working on the openvpn script, I noticed the produced config file had a lot of extra blank lines, so I tried to clean up the Jinja template. It turns out whitespace handling in Jinja2 is not trivial, and a template that may produce a satisfactory file format in some input data cases, produces a broken format (with missing newlines) in other cases, (usually if a if-statement adds a preceding and trailing newline, the next statement can not add it, and if the preceding if-statement then gets switched off, the next statement ends up adding text without a newline).

So to produce nicely looking files with manual whitespace control, a lot of care is required. To help me work on and test the template, I used an online template live parser: http://jinja.quantprogramming.com/

I haven't tried trim_blocks or lstrip_blocks, it seems having manual control is better.

I'd like to keep this task as the parent task for such template cleanup.

Details

Difficulty level
Unknown (require assessment)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Internal change (not visible to end users)

Event Timeline

jjakob changed the task status from Open to In progress.Apr 6 2020, 3:26 PM
jjakob triaged this task as Wishlist priority.
jjakob created this task.
jjakob created this object in space S1 VyOS Public.
erkin renamed this task from Controlling whitespace in Jinja templates to Controlling whitespace in Jinja templates (template cleanup parent task).Aug 30 2021, 7:37 AM
erkin set Issue type to Internal change (not visible to end users).
erkin removed a subscriber: Active contributors.
Viacheslav added a subscriber: Viacheslav.

There is nothing to do there, all checks for linter Jinja included to vyos-build.
Close it.