Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] HB doesn't iterate over array returned by function #243

Closed
al6x opened this issue May 18, 2012 · 7 comments
Closed

[bug] HB doesn't iterate over array returned by function #243

al6x opened this issue May 18, 2012 · 7 comments

Comments

@al6x
Copy link

al6x commented May 18, 2012

It seems that Handlebars doesn't iterate over array returned by function, it threats it as if statement.

Test case:

var template = Handlebars.compile(
  "peoples:<br/>{{#people}}name: {{name}}<br/>{{/people}}"
);var data = {
  people: function(){return [{name: 'Jim'}, {name: 'John'}]}
}
$('body').append(template(data));

The result will be peoples: name: instead of peoples: name: Jim name: John.

Try it online http://jsfiddle.net/HUcNP/

@wagenet
Copy link
Collaborator

wagenet commented May 18, 2012

My understanding is that Handlebars isn't meant to support function properties.

@al6x
Copy link
Author

al6x commented May 18, 2012

Hmmm, not sure about it, it support {{myModel.someAttributeAsFunction}} for example.

@wagenet
Copy link
Collaborator

wagenet commented May 18, 2012

My understanding is that it will work in some cases but isn't recommended. I may be mistaken though.

@jblotus
Copy link
Contributor

jblotus commented May 18, 2012

handlebars (at least outside of Ember.js) doesn't officially support functions as properties. You could do this even though it's really janky:

var context = {
  people: (function(){return [{name: 'Jim'}, {name: 'John'}]})()
}

see:
#140

@al6x
Copy link
Author

al6x commented May 18, 2012

Why not? Is there any reason for such limitation? It doesn't complicate syntax or API of mustache and seems perfectly valid and clear use case, why not support it?

#140

It seems that it's not actually a related issue, there's the discussion about the context of function, not about should it be called or not.

@jblotus
Copy link
Contributor

jblotus commented May 19, 2012

i don't necessarily disagree with it, especially since you can do computed props in Ember. I'm sure Yehuda has a much better reason.

@wagenet
Copy link
Collaborator

wagenet commented May 25, 2012

In Ember we actually modify the default Handlebars behavior to change it. If you want this sort of support, you should consider looking at what Ember does. I don't forsee the default Handlebars behavior changing any time soon so I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants