javascript - backbone.js: possible to push <script type="text/template> content to an external file -


i'm using backbone , in code have lot of text/template content i'd push external file (templates\name-of-template.js?) , load dynamically. there easy way this? when try link file <script type="text/template src='whatever'> not work.

probably easiest thing load file w/ ajax.

var myview = backbone.view.extend({     initialize: function() {         this.gettemplate();     },     gettemplate: function() {         var self = this;          $.ajax({ url: "some/html/template.html" }).done(function( content ) {             self.template = _.template( content );             self.render();         });     },     render: function() {         this.$el.html( this.template({}) );     } }); 

also, if using require.js can use text! plugin...

define( [ "underscore",     "backbone",     "text!some/html/template.html" ],     function( _, backbone, htmltemplate ) {      var myview = backbone.view.extend({         initialize: function() {             this.template = _.template( htmltemplate );             this.render();         },         render: function() {             this.$el.html( this.template({}) );         }     }); }); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -