【问题标题】:Ember.js compatibility with mustache librariesEmber.js 与 mustache 库的兼容性
【发布时间】:2012-09-22 01:37:13
【问题描述】:

我目前正在开发一个 PHP 站点,我计划与 Mustache PHP 一起使用,以便我可以在我的 PHP 渲染以及我的 javascript(ajax 驱动)页面更新中使用相同的 mustache 模板文件。在searching around 之后,我无法找到与 PHP 等效的 handlebars.js 库,尽管我更喜欢使用把手。

我正在决定是使用 Ember.js 还是 Backbone.js。我知道 Ember 使用车把,并且车把使用 mustache.js 中不存在的语法和功能,它是基于它的。我也知道 handlebars.js 可以很好地与 mustache 模板配合使用。

我倾向于 Ember 并且愿意在必要时分叉和更新 Mustache PHP 以与 Handlebars.js 一起使用。

但首先,Ember.js 能否与直胡须模板很好地配合使用?或者正确利用 Ember 是否还意味着使用只有车把支持的模板功能?

如果我必须分叉 PHP 库,我最想首先添加的主要车把功能是什么?

提前致谢,这将真正帮助我决定是否值得使用 Ember.js。

【问题讨论】:

    标签: php ember.js handlebars.js mustache


    【解决方案1】:

    Handlebar.js 在 Mustache(.php/.js) 语法上添加了一些“帮助程序”……但这些完全没用,因为 Mustache 已经很好地做到了:

    {{#each xyz}}...{{/each}} is the same as {{#xyz}}...{{/xyz}} in Mustache.
    {{#if xyz}}...{{/if}}     is the same as {{#xyz}}...{{/xyz}} in Mustache.
    {{#with xyz}}...{{/with}} is the same as {{#xyz}}...{{/xyz}} in Mustache.
    

    相比之下:

    {{#unless xyz}}...{{/unless}} is the same as {{^xyz}}...{{/xyz}} in Mustache.
    

    Ember.js 看起来非常像 handlebar.js,而 Backbone.js 似乎为与逻辑无关的 Mustache-Kind-of-rendering 一些输出添加了很多逻辑。

    我在一些小型和大型网站上使用 Mustache(php)。 Ajax 调用导致 Mustache 填写了一段 html,而 jQuery 用结果替换了一些 dom 元素。它就像一个魅力。

    对我来说:不要向 Mustache 添加逻辑,只需从 Handlebar.js 中删除逻辑(我想它也可以在没有那些“帮助者”的情况下工作。)

    【讨论】:

      【解决方案2】:

      我不需要使用 Ember,但确实注意到在我发布此问题后不久,其他人开始了 Handlebars parsing within PHPthis library is another approach 的项目。这些库是我一直在寻找的解决方案,因为仅使用 mustache 渲染器处理车把模板有很多潜在的复杂性。

      【讨论】:

        猜你喜欢
        • 2012-01-04
        • 2021-08-27
        • 2018-06-01
        • 1970-01-01
        • 2014-11-14
        • 1970-01-01
        • 1970-01-01
        • 2010-11-28
        • 1970-01-01
        相关资源
        最近更新 更多