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

item list not rendering #27

Closed
funston opened this issue May 4, 2010 · 4 comments
Closed

item list not rendering #27

funston opened this issue May 4, 2010 · 4 comments

Comments

@funston
Copy link

funston commented May 4, 2010

This is the output I get from running the example, are array iterators broken?

Joe's shopping card: <ul> <li></li><li></li></ul>

var view = {name: "Joe's shopping card",
            items: ["bananas", "apples"]}

var template = "{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>"

var html = Mustache.to_html(template,view);
@janl
Copy link
Owner

janl commented May 4, 2010

Can you write a test case for that? Can you check examples/ for existing tests? They all pass for me.

@natevw
Copy link

natevw commented May 5, 2010

I'm getting the same issue when putting the example from the project homepage into a CouchApp. If I use {{%IMPLICIT-ITERATOR iterator=test}}, then test is defined, but without it {{.}} yields nothing.

I'm starting to think the example is wrong, especially based on the documentation for the IMPLICIT-ITERATOR and for http://mustache.github.com/mustache.5.html. I think the {{.}} is only defined with the custom IMPLICIT-ITERATOR pragma, since it's not mentioned at all in the main mustache documentation.

To iterate, your array needs to contain objects eg:

var data = {"fruits" : [{"name" : "apple"}, {"name" : "orange"}, {"name" : "banana"]}
var template = "<ul>{{#fruits}}<li>{{name}}</li>{{/fruits}}</ul>"

Or you need to use IMPLICIT-ITERATOR:

var data = {"fruits" : ["apple", "orange", "banana"]}
var template = "<ul>{{%IMPLICIT-ITERATOR}}{{#fruits}}<li>{{.}}</li>{{/fruits}}</ul>"

The documentation for this port seems to conflate the two.

@janl
Copy link
Owner

janl commented May 5, 2010

good find, I'll look into updating the docs

@janl
Copy link
Owner

janl commented May 18, 2010

hm, no, sections for iteration and the implicit iterator pragma are separately documented. please reopen and suggest a patch to README.md if you think it needs clarification.

This issue was closed.
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