Skip to content

Instantly share code, notes, and snippets.

@mplatts
Created October 30, 2012 05:20
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 mplatts/3978446 to your computer and use it in GitHub Desktop.
Save mplatts/3978446 to your computer and use it in GitHub Desktop.
Backbone Layout Manager Simple Example
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://raw.github.com/documentcloud/underscore/master/underscore.js"></script>
<script src="https://raw.github.com/documentcloud/backbone/master/backbone.js"></script>
<script src="https://raw.github.com/tbranyen/backbone.layoutmanager/master/backbone.layoutmanager.js"></script>
</head>
<body>
<div id="app"></div>
<script id="main-layout" type="layout">
<span class="one"></span>
</script>
<script type="text/template" id="one-template">
<div class="view">
<h1><%= name %></h1>
<span class="two-a"></span>
<span class="two-b"></span>
</div>
</script>
<script type="text/template" id="two-template">
<div class="view">
<h2><%= name %></h2>
</div>
</script>
<script>
var LevelOneView = Backbone.LayoutView.extend({
template: '#one-template',
serialize: {name: "Level One"}
});
var LevelTwoView = Backbone.LayoutView.extend({
template: '#two-template',
serialize: {name: "Level Two"}
});
var main = new Backbone.Layout({
template: "#main-layout",
views: {
".one": new LevelOneView({
views: {
".two-a": new LevelTwoView(),
".two-b": new LevelTwoView()
}
})
}
});
$("#app").empty().append(main.el);
main.render();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment