Skip to content

Conformance Examples 0.1.0 — Render: trim-rendering

trim-open-strips-leading-template-text

{{~ /s }} strips whitespace from the preceding template text (trimOpen). The interpolated value itself is untouched.

Template

before  {{~ /s }}after

Context

{
    "s": "X"
}

Output

beforeXafter

trim-close-strips-trailing-template-text

{{ /s ~}} strips whitespace from the following template text (trimClose). The interpolated value itself is untouched.

Template

before{{ /s ~}}  after

Context

{
    "s": "X"
}

Output

beforeXafter

trim-both-strips-surrounding-template-text

{{~ /s ~}} strips whitespace from the template text on both sides of the tag.

Template

before  {{~ /s ~}}  after

Context

{
    "s": "X"
}

Output

beforeXafter

trim-open-does-not-touch-value-whitespace

trimOpen strips template text, never the interpolated value's own whitespace.

Template

before  {{~ /s }}after

Context

{
    "s": "   "
}

Output

before   after

trim-close-no-template-whitespace-is-no-op

trimClose is a no-op when the following template text has no leading whitespace to strip.

Template

before{{ /s ~}}after

Context

{
    "s": "X"
}

Output

beforeXafter

unescaped-trim-open-strips-leading-template-text

{{{~ /s }}} strips whitespace from the preceding template text; the unescaped value is untouched.

Template

before  {{{~ /s }}}after

Context

{
    "s": "X"
}

Output

beforeXafter

unescaped-trim-close-strips-trailing-template-text

{{{ /s ~}}} strips whitespace from the following template text; the unescaped value is untouched.

Template

before{{{ /s ~}}}  after

Context

{
    "s": "X"
}

Output

beforeXafter

with-block-trim-reaches-into-body

~ on the #with opener's close side and the /with closer's open side strips whitespace from just inside the block body, leaving text outside the block untouched.

Template

X{{#with y ~}}
  Z
{{~/with}}Y

Context

{
    "y": {}
}

Output

XZY

with-block-trim-reaches-outside-body

~ on the #with opener's open side and the /with closer's close side strips whitespace from the text surrounding the whole block, leaving the body untouched.

Template

X  {{~#with y }}Z{{/with~}}  Y

Context

{
    "y": {}
}

Output

XZY

each-block-trim-reaches-into-body-every-iteration

~ on the #each opener's close side and the /each closer's open side strips whitespace from just inside the loop body; the strip applies on every iteration since it is resolved on the body's own AST once, before any iteration runs.

Template

{{#each items ~}}
{{ this }}
{{~/each}}

Context

{
    "items": [
        "a",
        "b"
    ]
}

Output

ab

each-block-else-trim

~ on the {{else}} tag strips whitespace across the else-body boundary when the list is empty and the else branch renders.

Template

{{#each items ~}}
X
{{~else~}}
Y
{{~/each}}

Context

{
    "items": []
}

Output

Y

if-block-else-if-arm-trim

~ on an {{else if}} tag's open side strips the trailing whitespace of the previous arm's body, even though that arm — not the else-if arm — is the one that ends up rendering.

Template

{{#if a }}A
{{~else if b }}
B{{/if}}

Context

{
    "a": true
}

Output

A

if-block-else-trim

~ on a plain {{else}} tag strips whitespace across the arm/else-body boundary when the else branch renders.

Template

{{#if a }}A
{{~else~}}
B{{/if}}

Context

{
    "a": false
}

Output

B

unless-block-trim-reaches-outside-body

~ on the #unless opener's open side and the /unless closer's close side strips whitespace surrounding the whole block, leaving the body untouched.

Template

X  {{~#unless flag }}Z{{/unless~}}  Y

Context

{
    "flag": false
}

Output

XZY

comment-trim-both

~ on both sides of a comment tag strips the surrounding template text; the comment itself never renders anything.

Template

before  {{~! note ~}}  after

Output

beforeafter

assign-trim-both

~ on both sides of an assign tag strips the surrounding template text; the tag itself never renders anything.

Template

before  {{~= @local/t = "Lo" ~}}  after{{ @local/t }}

Output

beforeafterLo

Source fixture: render/trim-rendering.json