Skip to content

Instantly share code, notes, and snippets.

@thanpolas
Created February 4, 2013 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thanpolas/4706309 to your computer and use it in GitHub Desktop.
Save thanpolas/4706309 to your computer and use it in GitHub Desktop.
nodejs handlebars + layoutmanager + backbone
requirejs = require('requirejs'),
LayoutManager = require("backbone.layoutmanager"),
hbsCompiled;
requirejs(['handlebars-helpers'], function(){
hbsCompiled = require('../static/js/templates/hbsCompiled');
var hand = require('Handlebars');
});
LayoutManager.configure({
// Setting this option augments `Backbone.View` to work like `Layout`.
manage: true,
prefix: '',
/**
* Custom fetch to render templates
*/
fetch: function(path) {
return hbsCompiled[path];
}
});
// Create a header View and notice that simply providing a path to a template
// will automatically load it.
var Splash = Backbone.View.extend({
template: "splash",
serialize: function() {
return {backend: true};
}
});
var layout = new Backbone.Layout({
template: "main-layout",
views: {
"#app": new Splash({ el: false})
}
});
// Render the layout and echo out the contents.
layout.render().then(function() {
res.send(this.$el.html());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment