-
Notifications
You must be signed in to change notification settings - Fork 423
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
Iterator support esoteric behavior (keys) #9
Comments
In the implicit_iterator/ImplicitIterator.php, make a little change to the start key of the array. it'll not work. |
The current functionality is by design: Because PHP uses the same primitive for hashes and arrays, Mustache needs some way of determining whether a variable is iterable (i.e. an indexed array) or not (i.e. an associative array). The current implementation assumes that if an array does not have consecutive, zero-based array keys, it must be an associative array. And, if an array is an associative array, it is not "iterable" in the mustache sense of the word. |
Why not let the associative array iterated ? I cannt see the syntax |
Actually, it's not a matter of letting this implementation of Mustache be 'more powerful'. The current functionality is fundamental to Mustache. Given this view:
And this template:
You'll get something like:
But if you use the stuff variable instead:
You would get:
This is because, in Mustache, a section is either
and
In the case of
You could see how this is a problem, right? |
I just run over this yesterday while using Mustache. I think it's worth to share if someone runs into the same problem. I had an iterator that was keyed starting with 1.
While using it for a Mustache section, the section was rendered (once) but did not contain any sub values (Not using a pragma).
I wondered about that and checked out the tests in specific the one which iterates over an array. I rebuild that test scenario in my template and used the testdata as a comparison which did work. The testdata array is default keyed.
As this was the only difference I changed my keying to start with 0 instead of 1. This did the trick for the moment.
While I wanted to reproduce this yesterdays behavior to make a more specific issue report here today, I was not able to reproduce this any longer (!).
So if someone runs over a similar problem, in the end the fix was easy for me. I'm a bit disappointed because I can not reproduce it right now even when I revoke the changes I made to fix the problem.
The text was updated successfully, but these errors were encountered: