Reputation: 7181
So I'm trying to implement some handlebar directives to one of my templates, but I'm kind of lost on how to pass the JSON to the template so that it can make use of it in the directive.
Currently I have this in my View:
application = require 'application'
template = require('views/templates/appLayout')
module.exports = class AppLayout extends Backbone.Marionette.Layout
template: template, loggedin: true
el: "body"
regions:
content: "#content"
And this in the view's template:
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#"><i class="icon-leaf"> </i> Application</a>
<div class="nav-collapse"><!-- Other nav bar content -->
<!-- The drop down menu -->
<ul class="nav pull-right">
{{#if loggedin}}
<h1>Welcome back!</h1>
{{else}}
<input id="login" type="email" placeholder="E-mail" class="flat">
<input id="password_login" type="password" placeholder="Password" class="flat">
<button class="btn btn-primary btn-mini login btn-embossed">Sign in</button>
<button class="btn btn-danger btn-mini register btn-embossed ">Sign up</button>
{{/if}}
</ul>
</div>
</div>
</div>
</div>
<div id="content" class="container"></div>
Right now the template's else block is getting rendered, but I want the if block to get rendered. Does anyone know how to correctly implement this?
Upvotes: 0
Views: 2511
Reputation: 25994
You need to define the layout's serializeData
to send the JSON you need. You can see an example here: https://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/common/views.js
Documentation: https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.view.md#viewserializedata
Upvotes: 4