Escape double braces {{ ... }} in Mustache template. (templating a template in NodeJS)

Nick Jonas picture Nick Jonas · Dec 19, 2012 · Viewed 37.5k times · Source

I'm trying to template a template, like below:

{{{
{
  "name" : "{{name}}",
  "description" : "{{description}}"
}
}}}

{{{debug this}}}

<h1>{{name}}</h1>

Where I want to triple brackets to stay, but double brackets to be replaced with the JSON passed in. Anyone know the best way to do this without writing post-process JS code, and if not, is there a good nodeJS template engine for this type of scenario?

Answer

tmuecksch picture tmuecksch · Dec 13, 2013

As described in this Question handlebars doesn't support changing the delimiters. But you can escape the double braces with a backslash like this:

HTML:

... \{{ myHandlbarsVar }} ...