In a JQuery template in my project, I am trying to write out a variable which is an HTML string without encoding the HTML. When I just output the variable like so:
 ${description}
it results in the raw HTML string being outputted with tags and all like so:
<p>text <b>bold</b>  <i>italic</i></p>
But when I try to turn the markup into real tags at the same exact place in the code:
   {{html $description}}
doesn't output anything!
I tried a zillion ways of passing in the variable, but I think there's something going on in the html routine I'm not getting.
Thanks.
Update:
Here's how it's being called:
    this.$el.attr('data-id', tmplData.id).
          data('id', tmplData.id).html($.tmpl(this.template, tmplData));
Where this.template is the template file and tmplData is JSON which includes $description and the other variables needed.
Another update:
 {{html '<p>string</p>'}}
does behave as expected. But
 {{html $another_variable}}
fails to produce any output even when $another_variable doesn't have an HTML in it.
Another update:
I also tried:
 ${$item.html(description)}
and changed the call to the template to
 this.$el.attr('data-id', tmplData.id).
         data('id', tmplData.id).
         html($.tmpl(this.template, tmplData, {
            truncate: _.truncateStrip,
            html: _.html,
        }));
And wrote a custom html routine to pass through the string unchanged as was recommended:
 html: function(str) {
        return str;
    }
but still no dice.
The answer is:
{{html description}}
I tried that early on, but because I left stray spaces inside the curly brackets, it did not interpret properly.
:-(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With