node.js and Handlebars: HTML compiled is escaped

后端 未结 2 693
感动是毒
感动是毒 2020-12-15 08:40

Im using handlebars in a node aplication, and I have trouble.

This is the template index.html

{{CONTENT}}

This is the

相关标签:
2条回答
  • 2020-12-15 09:00

    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".

    <div class="entry">
      <h1>{{title}}</h1>
      <div class="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:

    <div class="entry">
      <h1>All About &lt;p&gt; Tags</h1>
      <div class="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})
    
    0 讨论(0)
  • 2020-12-15 09:04

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

    {{{CONTENT}}}
    
    0 讨论(0)
提交回复
热议问题