I was trying to create a basic app, using backbone, underscore, and Parse.
In my index.html, I tried including some scripts like this:
<script data-main=js/main src=../bower_components/requirejs/require.js></script>
<script type=text/template id=login-template src=js/templates/login.js>
When I tried to do the following on my backbone part, it did not work.
template: _.template($('#login-template').html());
// ...
render: function() {
this.$el.html(this.template());
}
However, when I changed my script, and added it directly in the html document, it worked fine.
<script type=text/template id=login-template>
<header id=header></header>
<div class=login>
<form class=login-form>
<h2>Log In</h2>
<div class=error style=display:none></div>
<input type=text id=login-username placeholder=Username />
<input type=password id=login-password placeholder=Password />
<button>Log In</button>
</form>
</script>
why is this? Is there any way to include templates from an external source in a <script>
tag?
(I cannot use $.get
for this case, as it's not supposed to use web server right now and keep getting XHR errors doing it normally.)