1

Not sure how to handle this scenario where JSON response contains HTML escaped values that needs to be converted to proper HTML tags.

"description": "Lorem adscs ireland <br/> marketed as in Europe"

rendered as text -

Lorem adscs ireland <br/> marketed as in Europe

Is it possible to resolve this issue. Please suggest.

Lokesh Yadav
  • 1,574
  • 5
  • 23
  • 50
  • 1
    possible duplicate of [Handlebars Template rendering template as text](http://stackoverflow.com/questions/7168469/handlebars-template-rendering-template-as-text) – Alexei Levenkov Sep 10 '15 at 07:03
  • Side note showing small template that does not work for you may help - so far looks like duplicate of regular "render unescaped HTML with handlebarJS" question. – Alexei Levenkov Sep 10 '15 at 07:04

2 Answers2

1

You can use SafeString to prevent handlbars from escaping the string.

Handlebars.registerHelper('link', function(text, url) {
  text = Handlebars.Utils.escapeExpression(text);
  url  = Handlebars.Utils.escapeExpression(url);

  var result = '<a href="' + url + '">' + text + '</a>';

  return new Handlebars.SafeString(result);
});

Handlebars docs - I can't link to the section but it's called Html Escaping

Clarkie
  • 7,490
  • 9
  • 39
  • 53
0

Perform a html decode function just before processing the string

akhil.cs
  • 691
  • 1
  • 5
  • 12