Answer the question
In order to leave comments, you need to log in
Unable to load template via require.js and text plugin. How to do it right and what is wrong?
Using require.js and the text plugin, I try to include the template in the dependency array
(
define(['backbone', 'text!templates/startPageTemplate.html'], function(Backbone, startPageTemplate) {
var startPageView = Backbone.View.extend({
el: '#content',
template: _.template(startPageTemplate),
initialize: function(){
this.render()
},
render: function(){
this.$el.html(this.template)
}
})
return startPageView;
})
) <h1> Hello this is start page </h1>
require.config({
paths: {
'jquery': 'libs/jquery/dist/jquery',
'underscore': 'libs/underscore/underscore',
'backbone': 'libs/backbone/backbone',
'templates': '../templates',
'text': 'libs/text/text'
}
})
require(['views/startPageView'], function(startPageView) {
new startPageView
})
<!DOCTYPE html>
<html>
<head>
<title>me app</title>
</head>
<body>
<div id="content"> </div>
<script src="public/js/libs/requirejs/require.js" data-main='public/js/main.js'></script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Run a server on localhost and serve everything with it. I understand that you just opened the html file in the browser.
here is an example there is a server part https://github.com/jmeas/gistbook on Express e
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question