MarionetteJS (Backbone.Marionette) Playground

A base template to use for building Backbone and Marionette applications. http://marionettejs.com

by Steven Senkus

HTML

<script src="http://underscorejs.org/underscore.js"></script>
<script src="http://backbonejs.org/backbone.js"></script>
<script src="http://marionettejs.com/downloads/backbone.marionette.js"></script>
<header>
<h1>A Marionette Playground</h1>
</header>

<article id="main">
</article>

<script type="text/html" id="sample-template">
  put some content <%= contentPlacement %>.
</script>

JavaScript

var App = new Marionette.Application();

App.addRegions({
    "mainRegion": "#main" 
});

// Create a module to contain some functionality
// ---------------------------------------------

App.module("SampleModule", function(Mod, App, Backbone, Marionette, $, _){
    
    // Define a view to show
    // ---------------------
    
    var MainView = Marionette.ItemView.extend({
        template: "#sample-template" 
    });
    
    // Define a controller to run this module
    // --------------------------------------
    
    var Controller = Marionette.Controller.extend({
        
        initialize: function(options){
            this.region = options.region
        },
        
        show: function(){
            var model = new Backbone.Model({
                contentPlacement: "heregfhfhgfhgfhgfhfghgfhgfh"
            });
    
            var view = new MainView({
                model: model    
            });
            
            this.region.show(view);
        }
        
    });
    

    // Initialize this module when the app starts
    // ------------------------------------------
    
    Mod.addInitializer(function(){
        Mod.controller = new Controller({
            region: App.mainRegion
        });
        Mod.controller.show();
    });
});

// Start the app
// -------------

App.start();