Whitespace Control
Omit whitespace from around the output of the template.
{{-EXPRESSION-}}
Whitespace may be omitted from either or both ends of a magic tag by including a
-
character by the braces. When present, all whitespace on that side will be
omitted up to the next tag, magic tag, or non-whitespace character. It also works with {{{expression}}}.
Parameters
- EXPRESSION
{Literal Expression|KeyLookup Expression|Call Expression|Helper Expression}
:An expression whose unescaped result is inserted into the page.
Examples
Basic Usage
<div>
{{-#if(user.isMarried)-}}
Mrs
{{-else-}}
Miss
{{-/if-}}
</div>
would render as:
<div>{{#if(user.isMarried)}}Mrs{{else}}Miss{{/if}}</div>
and
<div>
{{{- toMarkdown(content) -}}}
</div>
would render as:
<div>{{{ toMarkdown(content) }}}</div>
Span Elements
One use case is to remove spaces around span elements.
<div>
<span>
{{-#if(user.isMarried)-}}
Mrs.
{{-else-}}
Miss.
{{-/if-}}
</span>
{{- user.name }}
</div>
would render as:
<div>
<span>{{#if(user.isMarried)}}Mrs.{{else}}Miss.{{/if}}</span>{{ user.name }}
</div>
Empty Elements
Another would be to assure that empty elements are able to match the :empty
css pseudo-class (the whitespace that would be otherwise present prevents this),
while still being cleanly formatted for human consumption.
<div>
{{-! output the users name }}
{{-#if(user.name)}}
{{ user.name }}
{{/if-}}
</div>
would render as:
<div>{{-! output the users name }}{{-#if(user.name)}}
{{ user.name }}
{{/if-}}</div>