Handlebars Template rendering template as text

前端 未结 2 2141
误落风尘
误落风尘 2020-12-01 08:48

I created a helper in Handlebars to help with logic, but my template parses the returned html as text rather than html.

I have a quiz results page that is rendered a

2条回答
  •  情歌与酒
    2020-12-01 09:23

    Geert-Jan's answers is correct but just for reference you can also set the result to "safe" directly inside the helper (code from handlebars.js wiki)

    Handlebars.registerHelper('foo', function(text, url) { 
      text = Handlebars.Utils.escapeExpression(text);
      url = Handlebars.Utils.escapeExpression(url); 
      var result = '' + text + ''; 
      return new Handlebars.SafeString(result); 
    });
    

    With that you can use regular double handlebars {{ }} and handlebars won't escape your expression.

提交回复
热议问题