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 #158

Closed
rlightner opened this Issue Jan 24, 2012 · 7 comments

Comments

Projects
None yet
6 participants
@rlightner

rlightner commented Jan 24, 2012

<li lat="{{ll[0]}}" lng="{{ll[1]}}">{{name}}</li>

ll is a two item array [47, -122]

Is this valid or do I have to write a function to extra the item at index I want?

Thanks!

@bobthecow

This comment has been minimized.

Show comment
Hide comment
@bobthecow

bobthecow Jan 24, 2012

{{ll.0}} and {{ll.1}} will work in most mustache implementations... haven't tried it in mustache.js though :)

bobthecow commented Jan 24, 2012

{{ll.0}} and {{ll.1}} will work in most mustache implementations... haven't tried it in mustache.js though :)

@rlightner

This comment has been minimized.

Show comment
Hide comment
@rlightner

rlightner Jan 24, 2012

Thanks, I'll give that a try.

rlightner commented Jan 24, 2012

Thanks, I'll give that a try.

@mjackson

This comment has been minimized.

Show comment
Hide comment
@mjackson

mjackson Jan 30, 2012

Collaborator

Indeed, if you're using 0.5 (currently on master) you can do something like this:

mustache.render("{{a.0}}", {a: ['hi']})
=> 'hi'
Collaborator

mjackson commented Jan 30, 2012

Indeed, if you're using 0.5 (currently on master) you can do something like this:

mustache.render("{{a.0}}", {a: ['hi']})
=> 'hi'

@mjackson mjackson closed this Jan 30, 2012

@P48L0

This comment has been minimized.

Show comment
Hide comment
@P48L0

P48L0 May 9, 2012

this should be on the documentation, it's very usefull. You can even do this if you are int he current item: {{0}}

P48L0 commented May 9, 2012

this should be on the documentation, it's very usefull. You can even do this if you are int he current item: {{0}}

@piazera

This comment has been minimized.

Show comment
Hide comment
@piazera

piazera Dec 18, 2013

how can I use another {{variable}} as the index?
i.e. {{my_array.{{my_index}}}}

piazera commented Dec 18, 2013

how can I use another {{variable}} as the index?
i.e. {{my_array.{{my_index}}}}

@bobthecow

This comment has been minimized.

Show comment
Hide comment
@bobthecow

bobthecow Dec 21, 2013

@piazera You can't. Mustache feels like that's one step too far over the "logic-less" line.

bobthecow commented Dec 21, 2013

@piazera You can't. Mustache feels like that's one step too far over the "logic-less" line.

@JuergenSimon

This comment has been minimized.

Show comment
Hide comment
@JuergenSimon

JuergenSimon Jul 26, 2017

Why can't mustache do this like a normal person and use [0] for indexing? This is really messy.

JuergenSimon commented Jul 26, 2017

Why can't mustache do this like a normal person and use [0] for indexing? This is really messy.

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