Jquery / backbone / mustache / json html rendering as text string

Su is tired and I know I saw this before, but Google is not helping me create a one-page WP core theme. Data is only wordpress JSON API data, and I happily used the basic scheme for several projects, but this time it does not play well. He does this (showing html tags, not ... using them well):

enter image description here

here's the rendering code:

this.template = '<div class="post-list">{{#posts}}<article><h2>{{title}}</h2><span class="postcontent">{{content}}</span></article>{{/posts}}</div>'; if(this.model.get("rawdata").posts!=undefined && this.model.get("rawdata").posts.length>0) { var posts = []; for(i=0;i<this.model.get("rawdata").posts.length;i++) { posts[i] = new PostModel(this.model.get("rawdata").posts[i]); } this.postCollection = new PostCollection(posts); this.htm = Mustache.render(this.template,this.model.get("rawdata")); this.$el.empty().html(this.htm); log(this.htm) } else { //handle no-data result error } 
+6
source share
2 answers

Try putting before the variable name in the template

 {{& posts}} 

or

 {{& title}} 

All this is in the documentation.

+9
source

Another option is to use a triple mustache:

 {{{title}}} 

In the documentation. This option works in Nustache .

+8
source

Source: https://habr.com/ru/post/915438/


All Articles