Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember js, inject html tags in a template and render them as html

Let's say I have a very simple template :

<script type="text/x-handlebars" data-template-name='myTemplate'>
  <h1>{{name}}</h1>
  <div>{{content}}</div>
</script>

And a model that will look like that :

model = {
  name: 'My name',
  content: 'some content <a href="target">with a link</a> and some <i>italic</i> text'
}

I don't make the model, I load it from a web service and it will have (or not) html tags in it.

"My name" is properly rendered, but the content is rendered as a string and not interpreted as html.

How do I force ember to render html in a template

like image 596
fabien Avatar asked Dec 23 '13 11:12

fabien


1 Answers

Ok, sorry... By posting the question I realized it could be an handlebars question.

The answer was in handlebars documentation :

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

So My template has to be :

<script type="text/x-handlebars" data-template-name='myTemplate'>
  <h1>{{name}}</h1>
  <div>{{{content}}}</div>
</script>
like image 155
fabien Avatar answered Oct 07 '22 02:10

fabien