php - Ember.js 与 mustache 库的兼容性

标签 php ember.js handlebars.js mustache

我目前正在开发一个 PHP 网站,我计划将其与 Mustache PHP 一起使用这样我就可以在我的 PHP 渲染以及我的 javascript(ajax 驱动)页面更新中使用相同的 mustache 模板文件。在searching around之后,我无法找到适用于 PHP 的 handlebars.js 等效库,尽管我更愿意为所有内容使用 handlebars。

我正在决定是使用 Ember.js 还是 Backbone.js。我知道 Ember 使用 handlebars,而 handlebars 使用的语法和特性在它所基于的 mustache.js 中不存在。我也知道 handlebars.js 可以很好地使用 mustache 模板。

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

但首先,Ember.js 能否很好地与直 mustache 模板一起使用?还是正确利用 Ember 也意味着使用只有 handlebars 支持的模板功能?

如果我必须 fork PHP 库,我会渴望首先添加哪些主要的 Handlebars 功能?

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

最佳答案

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 中删除逻辑(我想它也可以在没有这些“助手”的情况下工作。)

关于php - Ember.js 与 mustache 库的兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12539997/

相关文章:

PHP天差计算错误

json - 如何将来自 REST-API 的 json 数据映射到 ember.js 模型?

javascript - 带选项参数的 Handlebars 编译函数

php - 使用正确的语法在 mysql 中添加行时出错

php - 长时间执行php cURL脚本而不更改php.ini设置

php - 自动提交 jeditable onchange

google-chrome - Ember App无法在Chrome中播放声音

facebook - Facebook 喜欢 Ember 应用程序

html - 将 Handlebars 脚本放在 ember 中的 div 中

javascript - 从字符串创建 dom 元素时添加多个类