Home > DeveloperSection > Forums > how to show “hello world” backbone-marionette.js?
ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    January-28-2015 10:19 PM

 ASP.Net JQuery  JavaScript  Backbonejs 
Ratings:


 1 Reply(s)
 638  View(s)
Rate this:

I am trying to trying a view using backbone +backbone-marionette.js..But I am able to get alert in route .But I want to display a view .But I am not able to display my template ?could you please tell me how to show my first view in angular

var firstpage = Backbone.View.extend({

template:"template/firstpage"

})



Kamlakar Singh
Kamlakar Singh

Total Post:28

Points:196
Posted on    January-28-2015 10:44 PM

There are many things you have to look at, to display that simple message.

this will initiate the router on document ready.

<script>

    $(document).ready(function () {

    router = new routers();

    Backbone.history.start();

})

Now in router function we will initialize our View and append it to body

showFirstPage:function(){

     var fView = new firstpage(); // view initialized

     $('body').append(fView.el); 

    }

el contains all the events and html , read about it here

For this to work we have to set some html to el of view on initialize

var firstpage = Backbone.View.extend({

template:_.template("<h1>Hello World<h1>"),

initialize:function(){

    this.$el.html(this.tempalte());

}

}) 


Don't want to miss updates? Please click the below button!

Follow MindStick