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

backbone.js, javascript, jquery, json, wordpress

Solution

Try putting & before the variable name in the template

{{& posts}}

or

{{& title}}

It's all in the documentation

Problem

soo tired and I know I've seen this before but Google's not helping I'm making a single-page backbone powered WP theme. The data is just the wordpress JSON API data & I've happily used backbone on a few projects now but this time its not playing nice.. It's doing this (showing html tags instead of.. well using them): here's the render 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 } ```

Original source