Skip to content

Instantly share code, notes, and snippets.

@mstapp
Created March 16, 2014 02:46
Show Gist options
  • Save mstapp/9577835 to your computer and use it in GitHub Desktop.
Save mstapp/9577835 to your computer and use it in GitHub Desktop.
blog - part 2 attach view to html
var App = new Backbone.Marionette.Application();
App.addRegions({
primaryRegion: "#primary-region",
});
Module.Controller = Marionette.Controller.extend({
start: function() {
// attach view to existing DOM element at '#primary-view'
this.view = new Module.View( {el: '#primary-view'} );
// Use attachView(), not show(), to preserve existing pre-rendered content
App.primaryRegion.attachView(this.view);
},
});
var isFirstView = true;
Module.Controller = Marionette.Controller.extend({
start: function() {
if (isFirstView) {
isFirstView = false;
this.view = new Module.View( {el: '#primary-view'} );
// Use attachView(), not show(), to preserve existing pre-rendered content
App.primaryRegion.attachView(this.view);
}
else {
this.view = new Module.View();
App.primaryRegion.show(this.view);
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment