RMontes13
RMontes13

Reputation: 2148

underscore _,template not recognize variables on template

I´m using underscore to load a html template with by require.js with text.js, like code bellow:

      template: _.template(listItemTemplate)    

      , render: function () {
            $(this.el).html(this.template(this.model.toJSON));
            return this;
        }

tvListItemTemplate.html

<h4><%= _id%></h4>

If i do console.log(this.model.toJSON()) it prints the following:

enter image description here

But the console give me this error:

enter image description here

I don´t understand why

Upvotes: 0

Views: 144

Answers (2)

RMontes13
RMontes13

Reputation: 2148

Sorry for that but it was a own stupid error in:

$(this.el).html(this.template(this.model.toJSON()));

Upvotes: 0

YD1m
YD1m

Reputation: 5895

Check with:

  $(this.el).html(_.template(listItemTemplate, this.model));

or

  template: function(x) {
      _.template(listItemTemplate, x);
  },
  render: function () {
        $(this.el).html(this.template(this.model));
        return this;
  }

Upvotes: 1

Related Questions