3

I just found this link to escape html in string with Handlebars.js: Handlebars.js disable escaping with noEscape option?

i.e var template = Handlebars.compile(source, {noEscape: true});

I am using Handlebars.Net in my project and I want to use the same configuration to escape html. Unfortunately I was not able to find any overload there to escape html.

It is just:

Handlebars.Compile(template)

Can you help me escaping html tags in that library?

Community
  • 1
  • 1
Raghav
  • 8,772
  • 6
  • 82
  • 106

2 Answers2

7

I expect you have figured this out by now, but Handlebars.net respects the Handlebars.js "triple 'stache" syntax, as in the following snippet. So change your {{}} to {{{}}} for the affected property and you should be golden.

<div class="entry">
  <h1>{{title}}</h1>
  <div class="body">
    {{{body}}}
  </div>
</div>
centralscru
  • 6,580
  • 3
  • 32
  • 43
  • Thanks for the answer. FYI, the next major version of Handlebars.Net is planned to also include the options hash, like handlebarsjs. – Rex M Feb 14 '16 at 16:02
0

This correct syntax is as follows. This is not identical to any other answer I could find so please don't delete it.

var handleBars = Handlebars.Create(new HandlebarsConfiguration { NoEscape = true });

var template = handleBars.Compile(sharingTemplate.Template);

var result = template(items);

Biraj Saha
  • 130
  • 1
  • 5