Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars.js disable escaping with noEscape option?

I have all my content pre-escaped, so rather than using the triple stash everywhere i would like to globally disable handlebars escaping. A quick search showed a similar feature which I can see in my build of handlebars, however I don't know how to turn it on.

The pull request is here: https://github.com/wycats/handlebars.js/pull/121

I've tried adding Handlebars.Compiler.options.noEscape = true in my code but it always comes back with options undefined. Even after defining the options its not picking it up. Does anyone know how I should be enabling this option in my script file? Thanks

like image 562
ant-depalma Avatar asked Mar 25 '12 12:03

ant-depalma


2 Answers

Try something like this:

var template = Handlebars.compile(source, {noEscape: true});
like image 62
Juho Vepsäläinen Avatar answered Sep 19 '22 12:09

Juho Vepsäläinen


Using the "triple-stash" {{{ is another option when you only want one variable in the template to not get escaped:

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

https://handlebarsjs.com/

like image 24
Rvanlaak Avatar answered Sep 19 '22 12:09

Rvanlaak