backbone.js - Passing variables into Handlebars template when rendering Marionette/Backbone View -
i'm using handlebars backbone , marionette. i'm compiling handlebars templates , storing them in object can referenced view definitions. i'm using layoutview , regions display various items need in ui.
what want pass (boolean) variables view such handlebars make decisions (via block helper {{#if varname}}
) render. clarity don't want persist data i'd rather not make them part of model i'm passing in rendered.
so i'm doing defining backbone.model , marionette.itemview normal, , trying pass in additional variables via initialize:
var newuser = new app.userview({ model: new app.usermodel(), initialize: function(){ this.isnewdoc = true } }); // display view in region using app.regions.maun.show(newuser); // ...etc.
what want able pass in , able refer variables such isnewdoc
in handlebars template, ideally via {{#if isnewdoc}}...{{/if}}
.
i've tried various permutations line this.isnewdoc = true
such isnewdoc: true
i'm not getting anywhere. doing wrong?
i override serializedata method when want this. can overriding tojson method in model, mention sent server when persist model. since these calculated attributes , not persistent attributes, don't sending them server. example below:
var newuser = new app.userview({ model: new app.usermodel(), serializedata: function() { return _.extend({ isnewdoc: true }, this.model.tojson()); } });
Hi
ReplyDeletevery useful and informative post thanks for sharing
Regards
Dinesh Kumar