Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 792
Nick Jonas Avatar asked Dec 19 '12 02:12

Nick Jonas


People also ask

How do you escape a Mustache?

Mustache does escape all values when using the standard double Mustache syntax. Characters which will be escaped: & \ " < > (as well as ' in Ruby >= 2.0 ). To disable escaping, simply use triple mustaches like {{{unescaped_variable}}} .

What is Moustache syntax?

Mustache is a web template system with implementations available for ActionScript, C++, Clojure, CoffeeScript, ColdFusion, Common Lisp, Crystal, D, Dart, Delphi, Elixir, Erlang, Fantom, Go, Haskell, Io, Java, JavaScript, Julia, Lua, .

What is Mustache in HTML?

A Mustache tag begins with two opening braces ( {{ ) and ends with two closing braces ( }} ). As you might have guessed, the {{ and }} delimiters are where Mustache gets its name from!

What are .Mustache files?

Mustache is a logic-less templating system. It permits you to use pre-written text files with placeholders that will be replaced at run-time with values particular to a given request. For more general information on Mustache, consult the mustache specification.


1 Answers

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 }} ... 
like image 88
tmuecksch Avatar answered Oct 17 '22 02:10

tmuecksch