Search code examples
javascriptjquerybackbone.jsunderscore.jsrequire

Unexpected behavoiur of define of requirejs


This code is working

define([
  'jquery',
  'underscore',
  'backbone'
], function($, _, Backbone,home_template) {
    var HomeView = Backbone.View.extend({    
        render: function() {  
            alert('abcd');
        }
    });

    return HomeView;  
});

this code is not working

define([
  'jquery',
  'underscore',
  'backbone',
  'text!modules/home/home_template.html'
], 
function($, _, Backbone,home_template) {
    var HomeView = Backbone.View.extend({    
        render: function() {  
            alert('abcd');
        }
    });  
    return HomeView;  
});

My directory structure is like webroot/modules/home/home_template.html

What can be the problem ??

Thanks


Solution

  • Problem might be in two possible places:

    1) Error in path(u can check in in fireBug or any other tool in network tab, look for 404 errors). It might be template or some other scripts placed inn wrong folder.

    2) Error in template syntax - in case of underscore be sure your template wrapped in <script type="template">.