0

I have a user model, each user has an artist and every artist has several albums. I'm trying to render a view to show a user profile. When I try to render the view I get the following error:

Uncaught ReferenceError: albums is not defined
(anonymous function) b.template.c underscore-min.js:30 
Backbone.View.extend.render profile.js:13 
Backbone.Router.extend.profile router.js:62 
...

It seems to be I'm not passing an album object to the template but I'm not using any album variable in that template, nor in the view. Here is the code for both:

View:

headerT = require('text!templates/user/profile_header.html');
  profileT = require('text!templates/user/profile.html');
  var profilesView = Backbone.View.extend({
  el: $('#main-container'),
  initialize: function(){
     this.template = _.template(profileT);                                                                                                  
     this.artist = this.model.get('artist');
  },

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

Template:

<div class="row">
    <div class="grid_3">
        <img src="<%=user.pict%>" class="frame" alt="">
        <span class="title">Username &ndash; <strong><%=user.username%></strong></span>
        <%if(current_user!=undefined && (current_user.get('is_admin') == true || current_user.get('id') == user.id)){%>
            <span class="title"><span class="icon user"></span> <a href="#/editProfile/">Edit Profile</a></span>
        <%}%>
        <%if(artist.active==true){%>
            <div><a href="#/artistProfile/">Go to Artist Profile</a></div>
        <%}%>
        <div class="separator"></div>
    </div>                                                                                                                                             
    <div class="clear"></div>
</div>    
Nocturn
  • 321
  • 6
  • 13
  • What's in `profileT` at the time the template compile occurs? – WiredPrairie Mar 13 '13 at 19:14
  • Now I get it, thanks @WiredPrairie, I had another variable called profileT in another view, where I stored the template I use to render the artist profile. It seems those variables are in the same scope even though they are in different files =S I changed the name of one of them and it worked. – Nocturn Mar 14 '13 at 17:50

1 Answers1

0

I changed the name of the variable that was holding the template and it worked. I had another variable with the same name, holding a different template (that had albums in it) in another file and it was loading that one instead. I thought the scope was different because it was in another file, but it didn't.

Nocturn
  • 321
  • 6
  • 13