将JSON传递给Backbone.Marionette视图的模板

时间:2013-06-01 21:40:14

标签: javascript backbone.js coffeescript handlebars.js marionette

所以我正在尝试为我的一个模板实现一些把手指令,但是我对如何将JSON传递给模板以使它可以在指令中使用它感到很遗憾。

目前我的观点中有这个:

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"

这在视图的模板中:

<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>

现在模板的else块正在渲染,但我希望if块被渲染。有谁知道如何正确实现这个?

1 个答案:

答案 0 :(得分:4)