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

Indexed arrays don't appear to work #2

Closed
edwardaux opened this issue Apr 4, 2015 · 10 comments
Closed

Indexed arrays don't appear to work #2

edwardaux opened this issue Apr 4, 2015 · 10 comments
Labels

Comments

@edwardaux
Copy link

Hi... I'm using the Swift1.2 branch, and am having trouble referencing array values via a direct index. eg. {{list.0}}. The following just outputs an empty string:

let input = [
    "list" : [ "aaa", "bbb" ]
]
let template = Template(string: "{{list.0}}")!
println(template.render(Box(input))!)

Interestingly, however, if I use {{list}}, then it outputs aaabbb. Just curious if fetching data from arrays using an index is supported?

Of course, it could also be that (as a Mustache newbie) I am using the wrong notation.

Thanks.

@edwardaux
Copy link
Author

Just doing a bit more fiddling, and it seems that referencing a dictionary by index seems to work. This means I can sort of support what I want by mapping my array input into a dictionary input:

let input = [
    "list" : [ "0":"aaa", "1":"bbb" ]
]
let template = Template(string: "{{list.0}}")!
println(template.render(Box(input))!)

Not quite as pretty, but manageable I guess.

@groue
Copy link
Owner

groue commented Apr 5, 2015

Hi @edwardaux.

list.0 is not standard Mustache, and GRMustache.swift does not support that feature.

You can use first and last if you want a quick access the first and last item of an array. Relevant documentation

@groue groue closed this as completed Apr 5, 2015
@groue groue added the wontfix label Apr 5, 2015
@groue
Copy link
Owner

groue commented Apr 5, 2015

I dislike a lot the non-standard syntax list.0, because even if it comes from the famous mustache.js, at the same time it jeopardizes any sane effort to introduce much needed features such as support for literals (context).

@edwardaux
Copy link
Author

Thanks for the quick reply @groue

Now that you mention it, my googling to find the list.0 notation was indeed from the mustache.js documentation.

While first and last are probably useful in the general case, my personal requirements need to be able to fetch the n'th element. No matter... as I said I can just switch to using a dictionary instead of an array.

Thanks again

@groue
Copy link
Owner

groue commented Apr 5, 2015

I'm happy you could find a workaround. Happy Mustache!

@groue
Copy link
Owner

groue commented Apr 9, 2015

@edwardaux FYI there is no Swift1.2 branch any longer: the master branch itself has switched to Swift1.2.

@edwardaux
Copy link
Author

Thanks for the pointer. Updating now.

@groue
Copy link
Owner

groue commented Apr 9, 2015

Cool. Were you able to have Carthage working? I've tried and failed so far.

@edwardaux
Copy link
Author

Yep, working for me - note, though, I was building a Mac OS X app (not iOS) using Xcode 6.3beta4 pointing to Swift1.2 branch.

I have downloaded Xcode 6.3 GA, but haven't had a chance to repoint to master branch and retest. I expect it should work OK though.

What problems are you having?

@groue
Copy link
Owner

groue commented Apr 9, 2015

I don't exactly remember now - it was a few weeks ago. It would get in a complete muddle in the middle of the two targets, the one for iOS and the one for OSX. But if you could do it, I could do it as well. I'll just try again. Thanks for telling me you did it, that's a light of hope :-)

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

No branches or pull requests

2 participants