I use Browserify to load a Backbone View. The view is rendering some html templates with underscore. The "tmpl2" method is generating an empty string when i load the template markup from the html template script. Are there any issues between browserify and underscore or why its rendering an empty string? (I use latest version of browserify, underscore, backbone, jquery)
View.js:
var $ = require('jquery');
var Backbone = require('backbone');
var _ = require('underscore');
Backbone.$ = $;
var View = Backbone.View.extend({
tmpl1: _.template("<p>hello: <%= name %></p>"), //HTML hardcoded
tmpl2: _.template( $.trim( $('#tmpl').html() ) ), //HTML from template
render: function(){
console.log( $.trim( $('#tmpl').html() ) ); //<p>hello: <%= name %></p> <-- OK
console.log( this.tmpl1({name : 'moe'}) ); //<p>hello: moe</p> <-- OK
console.log( this.tmpl2({name : 'moe'}) ); //(Emptystring) <-- WTF ???
}
});
module.exports = View;
index.html:
<script type="text/template" id="tmpl">
<p>hello: <%= name %></p>
</script>