Created
February 4, 2013 11:49
-
-
Save thanpolas/4706309 to your computer and use it in GitHub Desktop.
nodejs handlebars + layoutmanager + backbone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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