I'm using Marionette with requirejs and I would also like to use precompiled handlebars templates. How does this work?
Here my current setup:
require_main.js:
requirejs.config({
baseUrl: "/",
paths: {
'text': 'vendor/javascripts/text',
'backbone': "vendor/javascripts/backbone",
'backbone.wreqr': "vendor/javascripts/backbone.wreqr",
'backbone.babysitter': "vendor/javascripts/backbone.babysitter",
'jquery': "vendor/javascripts/jquery",
'jquery-ui': 'vendor/javascripts/jquery-ui',
'json2': "vendor/javascripts/json2",
'marionette': "vendor/javascripts/backbone.marionette",
'underscore': "vendor/javascripts/underscore",
'handlebars': "vendor/javascripts/handlebars"
},
shim: {
'underscore': {
exports: "_"
},
'backbone': {
deps: ["jquery", "underscore", "json2"],
exports: "Backbone"
},
'marionette': {
deps: ["backbone"],
exports: "Marionette"
},
'jquery-ui': ['jquery'],
'handlebars': {
exports: 'Handlebars'
}
}
});
require(["app"], function(MyApp){
MyApp.start();
});
app.js:
define(['marionette', 'handlebars', 'text!compiled.handlebars'], function(Marionette, Handlebars, Template_one) {
var MyApp = new Marionette.Application();
MyApp.addRegions({
mainRegion: "#main-region"
});
MyApp.StaticView = Marionette.ItemView.extend({
template: Template_one(context)
});
MyApp.on("initialize:after", function(){
var staticView = new MyApp.StaticView();
MyApp.mainRegion.show(staticView);
});
});
in my app.js I can get evth. work just fine with non compiled templates, like this:
...
var template = Handlebars.compile(Template_one)
var html = template(context)
template: html
...
but how to do it right with compiled templates?