Skip to content

Wiki: Indenting multi-line template / values #48

@suntong

Description

@suntong

Q:

Given:

{{define A}}
D
  E
    F
{{end}}

Or multi-line variables just like that, let's say I have the template setup like below:

A
  B
   C
     {{template A}} 

How do I make "template A" stay properly indented on rendering?

A:

Option 1:

A
  B
   C
     {{template A | indent 5 }} 

Option 2:

A
  B
   C
{{template A | pindent 5 }} 

Ref:

easygen/t_strings_test.go

Lines 186 to 201 in e7798da

{
`{{ indent 2 "a" }}`,
"a",
},
{
`{{ indent 2 "a\nb\nc" }}`,
"a\n b\n c",
},
{
`{{ pindent 2 "a" }}`,
" a",
},
{
`{{ pindent 2 "a\nb\nc" }}`,
" a\n b\n c",
},

PS. I like "Option 1" more because it is more intuitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions