Handlebars.js disable escaping with noEscape option?

后端 未结 4 1367
轻奢々
轻奢々 2021-02-20 00:35

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

相关标签:
4条回答
  • 2021-02-20 00:42

    Suppose,

    var template = "This is {{target}}";
    var target = "user's pictures";
    var result = Handlerbars.compile(template, {noEscape:true})({target:target});
    

    Now try to print result. There is an apostrophe in target string value. Which will not change by encoded string. If you will remove the {noEscape:true}from compile function then it will change.

    0 讨论(0)
  • 2021-02-20 00:51

    Try something like this:

    var template = Handlebars.compile(source, {noEscape: true});
    
    0 讨论(0)
  • 2021-02-20 00:55

    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/

    0 讨论(0)
  • 2021-02-20 01:02

    {noEscape:true} did not complile the template properly when tried with handlebarsv4.0.5.

    '{{{' works perfectly for me.

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