简体   繁体   中英

Ember.js compatibility with mustache libraries

I am currently developing a PHP site which I plan to use with Mustache PHP so that I can use the same mustache template files with my PHP rendering as well as with my javascript (ajax driven) page updates. After searching around , I was not able to find a handlebars.js equivalent library for PHP, although I would prefer to use handlebars for everything.

I am in the process of deciding whether to use Ember.js or Backbone.js. I know that Ember uses handlebars and that handlebars uses syntax and features not present in mustache.js, which it is based on. I also understand that handlebars.js works with mustache templates just fine.

I am leaning towards Ember and am willing to fork and update Mustache PHP to work with Handlebars.js if necessary.

But first of all, will Ember.js work nicely with straight mustache templates? Or does the proper leveraging of Ember also imply the use of template features that only handlebars supports?

If I do have to fork the PHP library, what are the main handlebars features I will be itching to add in first?

Thanks in advance, this will really help me decide if it is worth it for me to use Ember.js.

Handlebar.js adds some "helpers" on the Mustache(.php/.js) syntax... But these are completely useless as Mustache does this already very well:

{{#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.

In contrast:

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

Ember.js looks very much like handlebar.js, while Backbone.js seems to add a lot of logic to the logic-agnostic Mustache-Kind-of-rendering some output.

I'm using Mustache(php) on some small and large sites. Ajax calls result in Mustache filling out a peice of html and jQuery replaces some dom elements with the result. It's working like a charm.

To me: Don't add logic to Mustache, just remove the logic from Handlebar.js (I guess it will work without those "helpers" as well.)

I didn't need to use Ember but did notice that not long after I posted this question, someone else began the project of Handlebars parsing within PHP and this library is another approach . These libraries were the solution I was looking for since there were so many potential complications with treating handlebars templates using only a mustache renderer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM