jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 78 forks source link

Should mustache-sharp cope with array elements #21

Open nikkilocke opened 10 years ago

nikkilocke commented 10 years ago

In handlebars.js, you can access array elements using the syntax:

{{ item.[12] }} or {{ item.[propname] }}

It would be nice if mustache-sharp allowed the same (using the this[] indexer if the item was not an array).

jehugaleahsa commented 10 years ago

I wasn't aware of this feature. I am guessing the index can be a variable or a numeric literal. Some other folks are asking for numeric and string literals. I may incorporate these changes as a single release.

nikkilocke commented 10 years ago

I have checked an implementation of this into my branch, if you want to have a look. The syntax is .[<any characters other than ]>] The characters may be an integer (which returns an array element if the item is a 1-dimensional array, or tries this[int] if not, and finally tries this[string]), or arbitrary text, which is used as the string index for this[string]

kirtapatrik commented 10 years ago

This would be a great feature.

oscaruribe commented 9 years ago

Has this been implemented in the main branch?

I need to get first item in a list: {{bla.bla.items.[0].title}} This would be really great!

oscaruribe commented 9 years ago

@nikkilocke I saw your branch was way behind this one in commits. Is there anyway I could see just the code you added for supporting indexes? I'm in kind of a hurry to get this working and don't want to switch to Handlebars.net since I've done my own tags for this package:)

nikkilocke commented 9 years ago

I'm away on holiday right now, back next week. I thought the whole point of git was that you could easily see the changes for each individual commit? The information should all be there in my branch. If you can't winkle it out, send me another email, and I will have a look when I get home. Regards, Nikki

On 15 September 2015 09:42:22 BST, oscaruribe notifications@github.com wrote:

@nikkilocke I saw your branch was way behind this one in commits. Is there anyway I could see just the code you added for supporting indexes? I'm in kind of a hurry to get this working and don't want to switch to Handlebars.net since I've done my own tags for this package:)


Reply to this email directly or view it on GitHub: https://github.com/jehugaleahsa/mustache-sharp/issues/21#issuecomment-140324205

Sent from my Android device with K-9 Mail. Please excuse my brevity.