1

Background

I am trying to pass data to a precompiled handlebars template using Backbone.Marionette.

These template renders but data is not populated in template. Can anyone say what I am doing wrong?

Using the backbone.Marionette.handlebars plugin.

Code

mws.app = new Backbone.Marionette.Application();

mws.app.addRegions({
    page: "#page",
    contentContainer: "#mws-content-container"
});

mws.views.pageView = Backbone.Marionette.ItemView.extend({
    template:{
        type: 'handlebars',
        template: Handlebars.templates.page,
        serializeData: function(){
            return {
                'baseurl': "http://www.overstock.com/yo",
                'content': "content...?",
                'current_year': new Date().getFullYear(),
            }
        }
    }
});

mws.views.oasisRender = Backbone.Marionette.ItemView.extend({
    template:{
        type: 'handlebars',
        template: Handlebars.templates.oasis,
        serializeData: function(){
            return {
                'img1src': mws.homeDir+'img/oasis_1.png',
                'img2src': mws.homeDir+'img/oasis_2.png',
                'img3src': mws.homeDir+'img/oasis_3.png'
            };
        }
    }
});      

mws.app.router = Backbone.Marionette.AppRouter.extend({
    appRoutes: {
        'home' : 'homeRender'
    },
    homeRender: function(){
        mws.app.contentContainer.show(new mws.views.oasisRender());
    }
});

mws.app.addInitializer(function(){
    mws.app.page.show(new mws.views.pageView());
    mws.app.contentContainer.show(new mws.views.oasisRender());

});

mws.app.start();
xxmbabanexx
  • 8,256
  • 16
  • 40
  • 60
Joel Ephroni
  • 103
  • 1
  • 5
  • It is confusing as to what your actual question is. Do you have any idea of what the actual issue or part of code is? – xxmbabanexx Feb 28 '13 at 00:43
  • hmmm. not sure what is confusing about this. Marionette expects the template to be passed as value of attribute template. How do you pass data to the template if you are using precompiled handlebars templates? The above fails silently which is the best I have been abale to do. – Joel Ephroni Feb 28 '13 at 16:30
  • I have tried Handlebars.templates.oasis(data), using serializeData and passing it to the initializer: mws.app.contentContainer.show(new mws.views.oasisRender(data)); non of these works – Joel Ephroni Feb 28 '13 at 16:32
  • You seem to be missing huge sections of code that I think will be needed to solve your problem. I started a JSFiddle (http://jsfiddle.net/AsaAyers/xFC8z/2/), maybe you can fork it and add until you have a runnable example of your problem. I've never seen that format for the template attribute of a view. I've always seen them as either an actual template function, or a string that specifies the template's name. – Asa Ayers Mar 01 '13 at 03:09

0 Answers0