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
Allow for key references #298
base: master
Are you sure you want to change the base?
Conversation
…e.g.: `{{ key.{{ ref }} }}`
…: `{{ {{ ref }} }}`
@janl remember discussing this "back in the day." :) I'd love to see this get merged--or something like it. The syntax is a bit unwieldy and hard to read, but the objective (and the need for it) is spot on! Jan and I had discussed a syntax like {{@}} in blocks (this was prior to the dot pragma and the cascading scope being "stock" mustache, iirc). Maybe a revised variation of the example above:
I'd love the addition of something like this but for object key names as well:
Result would be:
Syntax is humorous if nothing else. :) Regardless of any of my blather, I'd love to see this idea reconsidered. Thanks for posting it (with code!) @indexzero |
Hi This issue is closest to my problem. I need to traverse object the same way sections work. Why not allowing object traversal in similar manner as sections? For example: {"obj": {"quux": "first", "foo": "second", "bar": "third"}} {{@obj}} Object traversal code {{/obj}} Now it would be really helpful that people could access keys and values. Maybe something like: {{@obj}} Would generate: quux: first This is kind in a line with mustache and syntax is better (?). Everything else should be made in javascript anyway. Thanks |
I want this to happen <3 |
I need this so bad! |
I implemented this in another c-template clone, in just this manner -- if a dotted elemented is referencing an array it will be used as an array index. I haven't actually had to use it often, but when needed it is indispensible. I have sometimes thought that using bracket syntax like @melkior I agree this can be very helpful. I implemented this using the |
We've been using this at Nodejitsu, and thought it might be useful
mustache.js
itself. Lets consider that you have a template the requires dynamic keynames like like:With a view:
This would render:
Thoughts? If you're interested in this I'll work up some tests.