javascripthtmlexpresshandlebars.jsmustache

Make indentation without new line?


I want to write some mustache code like this for readability:

{{this.$.Name}}

{{this.$.Name}}

but when I do, the HTML looks like this:

name name

I don't want any whitespace between the two names, I want it to look like this:

namename

But I want indentation in the .hbs file, is there a way to have both with mustache?


Solution

  • Handlebars has a feature called whitespace control:

    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.

    In your case, you'd do something like:

    {{this.$.Name~}}
    {{~this.$.Name}}
    

    View this Handlebars Playground for an interactive example.