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

Accessing Array item by index in template #68

Closed
nvenky opened this issue Apr 3, 2013 · 5 comments
Closed

Accessing Array item by index in template #68

nvenky opened this issue Apr 3, 2013 · 5 comments

Comments

@nvenky
Copy link

nvenky commented Apr 3, 2013

If there is an array {arr: ["a", "b"]}, I am not able to access the array by its index.

Eg., <span class="{{arr.0}}">{{arr.1}}</span>

The same syntax works in mustache.js
Mustache Js Reference

@spullara
Copy link
Owner

spullara commented Apr 3, 2013

That isn't in the spec but I'm not entirely against implementing it. Generally though I would suggest putting something in the view that names these things better and didn't expose the data model directly in the template.

https://github.com/mustache/spec

@spullara
Copy link
Owner

spullara commented Apr 7, 2013

I've decided that this is too low level to add to the core. However, I did write an extension if you need support for compatibility. You can find it here:

https://gist.github.com/spullara/5331831

@spullara spullara closed this as completed Apr 7, 2013
@ceefour
Copy link
Contributor

ceefour commented Jan 21, 2014

+1 for this. can this be re-decided?

For example, the accepted and most popular stackoverflow answer for this issue is the non-spec feature: see http://stackoverflow.com/a/17950970/122441

A mustache.java configuration option to the effect of "support non-spec features" would be awesome!

An unrelated note, if everybody follows just the HTML spec we'd never have JavaScript let alone AJAX. A spec-compliant configuration option is also used by Tomcat's org.apache.catalina. STRICT_SERVLET_COMPLIANCE (which curiously, defaults to false), PostgreSQL, MySQL, etc. so I hope this is a good enough alternative. :)

@spullara
Copy link
Owner

I'd rather leave stuff like this to extensions of the core rather than a bunch of options you can set. Mostly because I get asked for a tremendous number of features like this one, some of them completely orthogonal.

@ceefour
Copy link
Contributor

ceefour commented Jan 28, 2014

Is it possible to include your extension in mustache-java's distribution JAR? That'd make it really easy to use :)

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