Alex
Alex

Reputation: 3790

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

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):

enter image description here

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
            }

Upvotes: 6

Views: 3281

Answers (2)

absynce
absynce

Reputation: 1437

Another option is to use triple mustaches:

{{{title}}}

It's in the documentation too. This option works in Nustache as well.

Upvotes: 8

mccow002
mccow002

Reputation: 6914

Try putting & before the variable name in the template

{{& posts}}

or

{{& title}}

It's all in the documentation

Upvotes: 10

Related Questions