public
Last active

Using pre-compiled templates with Backbone.Marionette, require.js and the tpl template plugin

  • Download Gist
orders.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
define(function (require, exports, module) {
var ns = require('namespace'),
Backbone = require('use!backbone'),
Marionette = require('use!marionette'),
// the tpl require.js plugin extends the text plugin to compile the text into an underscore template
// The require.js optimizer will minify and concatenate them to your apps single JS
ordersViewTpl = require('tpl!templates/orders.html');
 
var Orders = ns.module();
 
Orders.Model = Backbone.Model.extend({});
 
Orders.Collection = Backbone.Collection.extend({
url: '/orders',
model: Orders.Model
});
 
Orders.Views.Details = Backbone.Marionette.ItemView.extend({
tagName: 'div',
// turns out, the signature of renderHtml matches a compiled template, so I can just
// override it with the template - simple and easy
renderHtml: orderDetailTpl
});
 
return Orders;
});

Thanks I think this will help me out as I am using the same plugin

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.