Search code examples
javascriptbackbone.jsmarionette

How to render root layout in Marionettejs?


Based on this fact, Region in Application is deprecated. How do you render the root layout? Simplely new the RootLayout() will not render the layout view. I know call region show() function will render layout, but since there is no region on Application object. How do you render the root layout?

The document suggest the following way, but it doesn't work.

I defined root layout like this:

var RootView = Marionette.LayoutView.extend({
  el: 'body'
});

Then render the root layout like this:

var canvasApp = new Marionette.Application();
canvasApp.on('start', function() {
    canvasApp.rootView = new RootLayout();
}
$(document).ready(function(){
    canvasApp.start();

});

Solution

  • It could be as simple as

    var RootView = Marionette.LayoutView.extend();
    var rootView = new RootView();
    rootView.render().$el.appendTo( document.body ); // or a selector
    

    or

    var RootView = Marionette.LayoutView.extend();
    var rootView = new RootView({ el: '#app' });
    rootView.render();
    

    or, as in your case

    var RootView = Marionette.LayoutView.extend({
      el: 'body'
    });
    var rootView = new RootView();
    rootView.render(); // just remember to render it