Skip to content Skip to sidebar Skip to footer

Node.js And Handlebars: Html Compiled Is Escaped

Im using handlebars in a node aplication, and I have trouble. This is the template index.html {{CONTENT}} This is the code var fs = require('fs'); var handlebars = require('handle

Solution 1:

From handlebarsjs.com :

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash".

<divclass="entry"><h1>{{title}}</h1><divclass="body">
    {{{body}}}
  </div></div>

with this context:

{
  title: "All about <p> Tags",
  body: "<p>This is a post about &lt;p&gt; tags</p>"
}

results in:

<divclass="entry"><h1>All About &lt;p&gt; Tags</h1><divclass="body"><p>This is a post about &lt;p&gt; tags</p></div></div>

However from my point of view it may defeat the purpose of having a template separated than you're js file.

If you use precompile then use noEscape option:

handlebars.precompile(content, {noEscape: true})

Solution 2:

You'd want to use the 'triple stash' in your template:

{{{CONTENT}}}

Post a Comment for "Node.js And Handlebars: Html Compiled Is Escaped"