Search code examples
backbone.jsmarionettehandlebars.js

Handlebars template - "tilde" in if statement


We have statement like:

{{~#if someCondition ~}} 
<div class="whyweneedtildehere"></div> 
{{~/if~}}

What is the difference between simple if statement and if statement with "~" in handlebars templates?


Solution

  • It is called a tilde, which might help you google it further.

    The Handlebars docs answers your question in detail.

    Template whitespace may be omitted from either side of any mustache statement by adding a ~ character by the braces. When applied all whitespace on that side will be removed up to the first handlebars expression or non-whitespace character on that side.