lines

Splits a string on ' ' only.

It does not strip carriage returns, so "\r\n" endings leave a trailing "\r" on each line, and a trailing newline produces a final empty element.

InputArgumentsReturnsstringno arguments[]string[]byteno arguments[][]byte
Source
BasicSource

Splits the value into lines on "\n".

Given

{"body": "first\nsecond\nthird"}

Template

{{ body | lines }}

Result

[
  "first",
  "second",
  "third"
]
Blank linesSource

Keeps blank lines as empty elements, so the line count matches the source.

Given

{"body": "alpha\n\ngamma"}

Template

{{ body | lines }}

Result

[
  "alpha",
  "",
  "gamma"
]
SingleSource

Returns a single-element slice when the value has no newline.

Given

{"body": "just one line"}

Template

{{ body | lines }}

Result

[
  "just one line"
]
Trailing newlineSource

Yields a final empty element when the value ends with a newline.

Given

{"body": "a\nb\n"}

Template

{{ body | lines }}

Result

[
  "a",
  "b",
  ""
]