5

I am trying to parse a string to html in handlebars.

Example: in .js file

let url = 'http://google.com';
let textref = `<a href=${url}>Click here</a>`

in .hbs file

{{textref}}

Expected output : Click here text holding the hyperlink
Actual output : <a href=http://google.com>Click here</a>

Actual output is the string instead of text reference holding the hyperlink.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
Prem
  • 5,685
  • 15
  • 52
  • 95

2 Answers2

7

Replace {{textref}} with {{{textref}}} in your code.

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

Ref

Vivek
  • 2,665
  • 1
  • 18
  • 20
5

Use the escape {{{ syntax:

{{{textref}}}
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79