Handlebars not fully compatible with mustache as claimed. #425

Closed
AshHeskes opened this Issue Feb 1, 2013 · 13 comments

Comments

Projects
None yet
7 participants
@AshHeskes

After looking into moving to Handlebars from Mustache.js due to better helpers support, I noticed that many features of Mustache.js are not compatible with handlebars.

If this is intended it would be great if you put on your website

Handlebars is a flavour of Mustache templates....

Instead of

Mustache templates are compatible with Handlebars, so you can take a Mustache template, import it into Handlebars, and start taking advantage of the extra Handlebars features.

Here is a list of features I spotted that are lacking compatibility.

Functions

While simple functions express as..

    var context = {
            firstname: 'Ash',
            lastname: 'Heskes',
            fullname: function(){
                return this.firstname + ' ' + this.lastname;
            }
        }

Work fine, but lambdas do not.

As explained in the Mustache spec.

When the value is a callable object, such as a function or lambda, the object will be invoked and passed the block of text. The text passed is the literal block, unrendered. {{tags}} will not have been expanded - the lambda should do that on its own. In this way you can implement filters or caching.

Template:
    {{#wrapped}}
      {{name}} is awesome.
    {{/wrapped}}
Hash:
    {
      "name": "Willy",
      "wrapped": function() {
        return function(text) {
          return "<b>" + render(text) + "</b>"
        }
      }
    }
Output:
    <b>Willy is awesome.</b>

Parent Properties

Also referencing parent Objects and properties is handled by default in Mustache.js.

Template:
    <ul>
    {{#items}}
        <li>
            <span>Item {{.}} for user {{username}}</span>
        </li>
    {{/items}}
    </ul>
Hash:
    var context = {
        items: [1,2,3,4,5]
        username: 'Ash' 
    }
Output:
    <ul>
        <li>
            <span>Item 1 for user Ash</span>
        </li>
        <li>
            <span>Item 2 for user Ash</span>
        </li>
        <li>
            <span>Item 3 for user Ash</span>
        </li>
        <li>
            <span>Item 4 for user Ash</span>
        </li>
        <li>
            <span>Item 5 for user Ash</span>
        </li>
    </ul>

Mustache.js looks up the current context Object for the property if it can't be found Mustache.js continues to lookup the parent tree until it finds the named property.

@theturtle32

This comment has been minimized.

Show comment Hide comment
@theturtle32

theturtle32 Jul 29, 2013

This is definitely biting us too. I switched over to using Handlebars on the front-end, while still continuing to use Mustache on the backend (in Ruby, Mustache renders way faster than the Handlebars implementation, due to the fact that the only available implementation of Handlebars in Ruby just uses the official JavaScript implementation via TheRubyRacer).

We're specifically running into the issue where Handlebars, unlike Mustache, does not traverse up through parents to find referenced properties within a {{#... block}}

Not sure if there's a reasonable workaround for this...

This is definitely biting us too. I switched over to using Handlebars on the front-end, while still continuing to use Mustache on the backend (in Ruby, Mustache renders way faster than the Handlebars implementation, due to the fact that the only available implementation of Handlebars in Ruby just uses the official JavaScript implementation via TheRubyRacer).

We're specifically running into the issue where Handlebars, unlike Mustache, does not traverse up through parents to find referenced properties within a {{#... block}}

Not sure if there's a reasonable workaround for this...

@cansin

This comment has been minimized.

Show comment Hide comment
@cansin

cansin Aug 29, 2013

I am experiencing the same issue with Handlebars. It should traverse up to parent context as Mustache does.

cansin commented Aug 29, 2013

I am experiencing the same issue with Handlebars. It should traverse up to parent context as Mustache does.

@csalch

This comment has been minimized.

Show comment Hide comment
@csalch

csalch Nov 11, 2013

Just ran into the parent context issue with a bunch of complex mustache templates as well. Is there any planned fix?

csalch commented Nov 11, 2013

Just ran into the parent context issue with a bunch of complex mustache templates as well. Is there any planned fix?

@daankuijsten

This comment has been minimized.

Show comment Hide comment
@daankuijsten

daankuijsten Nov 22, 2013

The workaround is to add:

../

in front of your nested object like this:

{{#if items}}{{../username}}{{/if}}

The workaround is to add:

../

in front of your nested object like this:

{{#if items}}{{../username}}{{/if}}
@JustBlackBird

This comment has been minimized.

Show comment Hide comment
@JustBlackBird

JustBlackBird Jul 1, 2014

As for context resolving Handlebars does not follow Mustache specs. It was discussed in #148 but it seems that discussion is stuck =)

As for context resolving Handlebars does not follow Mustache specs. It was discussed in #148 but it seems that discussion is stuck =)

@AshHeskes

This comment has been minimized.

Show comment Hide comment
@AshHeskes

AshHeskes Jul 2, 2014

In that case the handlebars.js website should be updated to reflect that handlebars is not nor intends to be compatible with mustache.js

It would be great it the handlebars team actually bothered to look at this issue properly. It is not a feature request nor a bug report. It is simply to help them correctly inform devs looking to move from directly from mustache.js to understand the caveats, then make the decision to..

a) Move their code base to the equivalent handlebars format (should it exist).
b) Not waste their time switching out mustache.js and debugging handlebars, due to false claims made on handlebars website.

It is really not that complicated..... update the damn website.

In that case the handlebars.js website should be updated to reflect that handlebars is not nor intends to be compatible with mustache.js

It would be great it the handlebars team actually bothered to look at this issue properly. It is not a feature request nor a bug report. It is simply to help them correctly inform devs looking to move from directly from mustache.js to understand the caveats, then make the decision to..

a) Move their code base to the equivalent handlebars format (should it exist).
b) Not waste their time switching out mustache.js and debugging handlebars, due to false claims made on handlebars website.

It is really not that complicated..... update the damn website.

@JustBlackBird

This comment has been minimized.

Show comment Hide comment
@JustBlackBird

JustBlackBird Jul 3, 2014

I do not think the maintainers want to throw away Mustache compatibility they already have. But I would like to listen @wycats opinion to make the situation clear. Is there any chance that Mustache and Handlebars will be fully compatible?

I do not think the maintainers want to throw away Mustache compatibility they already have. But I would like to listen @wycats opinion to make the situation clear. Is there any chance that Mustache and Handlebars will be fully compatible?

@AshHeskes

This comment has been minimized.

Show comment Hide comment
@AshHeskes

AshHeskes Jul 3, 2014

It's not a case of throwing away compatibility they have. It's simply a case of updating their information to accurately portray the situation. While Handlebars is mostly compatible with Mustache it is not fully compatible and they should inform devs of this fact instead of purporting full compatibility.

This isssue has been open for a long time, and the information on the website has remained the same despite it's incorrectness. This needs to be changed, irrespective of whether the maintainers intend to implement the missing features.

Up until the point that they have made a decision to either implement or ignore the missing features the fact remains, it is not fully compatible.

It's not a case of throwing away compatibility they have. It's simply a case of updating their information to accurately portray the situation. While Handlebars is mostly compatible with Mustache it is not fully compatible and they should inform devs of this fact instead of purporting full compatibility.

This isssue has been open for a long time, and the information on the website has remained the same despite it's incorrectness. This needs to be changed, irrespective of whether the maintainers intend to implement the missing features.

Up until the point that they have made a decision to either implement or ignore the missing features the fact remains, it is not fully compatible.

@AshHeskes

This comment has been minimized.

Show comment Hide comment
@AshHeskes

AshHeskes Jul 3, 2014

I sent this pull request to update the information on the handlebars website yesterday, Which was closed almost immediately and IMO without reasonable consideration.

In light of that discussion I have resubmitted this pull request today.

I sent this pull request to update the information on the handlebars website yesterday, Which was closed almost immediately and IMO without reasonable consideration.

In light of that discussion I have resubmitted this pull request today.

@kpdecker kpdecker modified the milestones: 2.0, Next Jul 5, 2014

@kpdecker

This comment has been minimized.

Show comment Hide comment
@kpdecker

kpdecker Jul 6, 2014

Collaborator

Did a differential on the features here. Our opinion is that currently:

Missing:

  1. The implicit recursive lookup
  2. Standalone mustache line stripping
  3. Alternative delimiters
  4. Mustache-style lambdas

Still in the process of investigating the feasibility but our goal is to implement:

  • (1) behind a flag as this has a significant performance hit if implemented across the board
  • (2) for all users

These are unlikely to be implemented and will be documented:

  • (3) is unlikely to be feasible due to our use of jison for parsing
  • (4) conflicts with Handlebars-style lambdas and this is an optional feature per the mustache spec.
Collaborator

kpdecker commented Jul 6, 2014

Did a differential on the features here. Our opinion is that currently:

Missing:

  1. The implicit recursive lookup
  2. Standalone mustache line stripping
  3. Alternative delimiters
  4. Mustache-style lambdas

Still in the process of investigating the feasibility but our goal is to implement:

  • (1) behind a flag as this has a significant performance hit if implemented across the board
  • (2) for all users

These are unlikely to be implemented and will be documented:

  • (3) is unlikely to be feasible due to our use of jison for parsing
  • (4) conflicts with Handlebars-style lambdas and this is an optional feature per the mustache spec.
@AshHeskes

This comment has been minimized.

Show comment Hide comment
@AshHeskes

AshHeskes Jul 15, 2014

Now that this has been clarified can you please update the website in the interim to correct the claim about Mustache compatibility.

Now that this has been clarified can you please update the website in the interim to correct the claim about Mustache compatibility.

kpdecker added a commit that referenced this issue Aug 14, 2014

Update compatibility documentation
Provides an official statement regarding the issues discussed in #425
@kpdecker

This comment has been minimized.

Show comment Hide comment
@kpdecker

kpdecker Aug 25, 2014

Collaborator

Documentation has been updated. The site update will go out with the next push.

Collaborator

kpdecker commented Aug 25, 2014

Documentation has been updated. The site update will go out with the next push.

@kpdecker kpdecker closed this Aug 25, 2014

@kpdecker

This comment has been minimized.

Show comment Hide comment
@kpdecker

kpdecker Aug 26, 2014

Collaborator

Released in v2.0.0-beta.1

Collaborator

kpdecker commented Aug 26, 2014

Released in v2.0.0-beta.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment