0

Classic problem. Want to see html rendered but I'm seeing text in the browser. Whether I tell handlebars js to decode it or not in template ( three curly braces vs two - {{{myHtmlData}}} vs {{myHtmlData}} ) doesn't get me there. Something about the JSON being returned via the model.fetch() has this html data wrapped up in such a way that it is resistant to the notion of displaying as HTML. It's always considered a string whether encoded or decoded so it always displays as text.

Is this just something backbone isn't meant to do?

The technologies involved here are:

    backbone.marionette
    handlebars.js
    .NET Web API
Robert
  • 828
  • 2
  • 13
  • 28
  • using Backbone.Marionette and Handlebars here, {{{ }}} worked fine out of the box. Not sure it would make a difference but you can try to pass your strings to the Handlebars.SafeString constructor: `var html = new Handlebars.SafeString('
    foo
    ')`
    – maxlath Feb 12 '15 at 15:58

1 Answers1

0

Your data is being escaped automatically. It's a good thing, but since you're sure the data is a safe HTML. Use {{{}}} as in this other question Insert html in a handlebar template without escaping .

Community
  • 1
  • 1
P. R. Ribeiro
  • 2,999
  • 1
  • 19
  • 20
  • Thanks for the response. As indicated in the question, three braces was tried. No dice. Not sure why that doesn't work. Thought that's what it was for. The only answer appears to be on the back end. Just don't send encoded html. Tried that and it works. Haven't found a client side solution other than pulling the data from the model, doing a JavaScript decode on it and then creating another model. I've done that and it works as well. Sort of lose some of the benefit of the natural flow of the framework and templating though. – Robert Feb 19 '15 at 14:56