【问题标题】:Handlebars templates in HAML using Ember.js使用 Ember.js 的 HAML 中的车把模板
【发布时间】:2012-09-07 00:32:35
【问题描述】:

我正在寻找一种在嵌入 Rails 3.2 项目的 Ember.js 应用程序中使用 HAML 编写 Handlebars 模板的方法。

Handlebars 是 1.0.rc.1,需要 ember-rails gem 0.7.0
Ember 是 1.0.pre-90-g60e3c05

无论如何,我的模板现在看起来像这样:

<div id="container">
  This is my test
</div>

我希望它是这样的:

#container
  This is my test

顺便说一句,我看过 James Harton 的 Hamlbars,但我不知道如何让它发挥作用。它一直输出Ember.TEMPLATES["templates/choose_resort"] = Ember.Handlebars.compile("This is my test"); 而不是预期的:

<div id="container">
  This is my test
</div>

(即使返回的似乎未编译的代码中也缺少 div 块)

任何提示将不胜感激。 提前致谢。

【问题讨论】:

  • hamlbars 对我有用 - 它输出 JS(正如您提到的那样),因此您应该将文件命名为 .js.hamlbars 并将其包含在您的清单中。

标签: haml ember.js


【解决方案1】:

试试新的Emblem.js。它比 HAML 更接近 Slim,但如果你喜欢缩进模板语言和 Ember.js,你会得到最干净的结果。

而且是Ember.js推荐的guide

【讨论】:

  • 感谢您提供这么棒的资源!
【解决方案2】:

如何分三步安装hamlbars:guide

【讨论】:

    【解决方案3】:

    有一个名为 Hamlbars 的 github 项目。它看起来像一个很棒的项目,我还没有在项目中使用它,但它看起来很有希望。

    这个:

    = hb 'App.widgetController.title'
    

    将呈现:

    {{App.widgetController.title}}
    

    还有这个:

    %ul.authors
      = hb 'each authors' do
      %li<
        = succeed ',' do
          = hb 'lastName'
          = hb 'firstName'
    

    将渲染到

    <ul class="authors">
      {{#each authors}}
        <li>{{lastName}}, {{firstName}}</li>
      {{/each}}
    </ul>
    

    我看了看,我确定这正是您要找的。​​p>

    干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多