I think the best way is to use a constructor. Create a layout rendering class.
App.RenderedLayout = Marionette.Layout.extend({ render: function () { if (this.onRender) { this.onRender(); } return this; }, constructor: function(){ this._ensureElement(); this.bindUIElements(); Marionette.Layout.prototype.constructor.apply(this, slice(arguments)); } });
Then you can take full advantage of Marionette.
App.module('Some.Page', function (Mod, App, Backbone, Marionette, $, _) { Mod.SomeLayout = App.RenderedLayout.extend({ el: '#renderedDiv', events: { 'click .something': 'onSomethingClick' }, regions: { 'innerRegion': '#innerRegion' }, ui: { something: '.something div' }, initialize: function () { }, onSomethingClick: function(e){ return false; } }); Mod.addInitializer(function(){ App.addRegions({renderedRegion: '#renderedDiv'}); Mod.someLayout = new Mod.SomeLayout(); App.renderedRegion.attachView(Mod.someLayout); }); });
source share