Skip to content

Render a template with keeping indentation level of multi-line strings #691

@inf17101

Description

@inf17101

I have the following issue with the default rendering:

name: some name
data:
  key1: |
    {{value1}}

If I substitute it with a multi-line string using the default rendering syntax like above, then indentation level is lost and the resulting yaml is invalid:

substitution_string: Line1\nLine2\nLine3

name: some name
data:
  key1: |
    Line1
Line2
Line3

What I need per default is:

name: some name
data:
  key1: |
    Line1
    Line2
    Line3

I have tried out to register a partial because then the indentation level is kept and the rendering is fine. But then I need a custom syntax for my users like {{> indent value1}} (assume here the partial is registered with name 'indent').

Is there a programmatic way in the handlebars-rs library to enable to keep indentation level before rendering and disable it afterwars? I need it for one field and I need to change the default behavior.

What I have tried out: Register a template with is_partial = true, but the member and the Template::compile2 to define TemplateOptions is also private.

Is there any way to keep indentation level with the default syntax without defining special helpers or custom syntax?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions