Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
            }
like image 866
Alex Avatar asked May 10 '12 20:05

Alex


2 Answers

Try putting & before the variable name in the template

{{& posts}}

or

{{& title}}

It's all in the documentation

like image 175
mccow002 Avatar answered Nov 15 '22 07:11

mccow002


Another option is to use triple mustaches:

{{{title}}}

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

like image 22
absynce Avatar answered Nov 15 '22 09:11

absynce