-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Dot notation for object keys with dots in the name #343
Comments
that would break dot notation for diving into nested objects: https://github.com/janl/mustache.js#variables (last example) |
How would it break it? I'm saying it would be useful to be able to escape dots in variable names, so that dot notation can still be used, but also allow variable names and nested var names that themselves contain dots. Sent from my iPhone
|
This naive solution is ugly but would solve the issue: {{abc.contains.dots.doesnt}} Sent from my iPhone
|
ah, escapes, that could work :) On 20 Nov 2013, at 16:28 , William P. Riley-Land [email protected] wrote:
|
I’d +1 a patch. |
You know, I was thinking the other day that it would be really handy for me if PHP could have spaces in variable names. It's not that hard to work around it:
… but it really chafes that there are, like, 10 characters I'm not allowed to use in variable names. I wish I could do something more like this:
So rather than change my code and data to adapt to the (few) restrictions placed on me by the language, I'd like the core language to adapt to something that's more convenient to me. I just thought I'd throw it out there. :) |
Haha, might work better if you file a bug on the PHP issue tracker ;) I'll give the patch a go! |
Seriously though, Mustache lets you do almost anything you want. You can't start a name with Mustache's stance has always been that you should make your data / view model fit the template, not the other way around. |
@bobthecow sure, but adding -escapes seems innocent enough, if it can be done nicely. |
@janl But what about the previously perfectly acceptable |
so? |
It's a backwards compatibility break and a non-standard mustache behavior to work around something that should probably be solved by a proper view model anyway. But it's your call, not mine. I'm just sharing my opinion :) |
I'll close this issue due to inactivity. If it's still relevant, leave a comment and I'll reopen. |
you can replace dots with "" before you deserialize your json |
Dudes, please help! i have object key properties with dots in name. I need to set nested properties, it doesnot work. set(object, 'a.b.c.d',12345) sets obj = {a: {b: {c:{d:12345}}}} , |
You should be able to call it like this: obj['a.b.c.d']; |
Was affected by this bug, been able to workaround but would be very good to see it fixed. |
@DanielUranga yah :'( |
I solved with the dot-object lib (https://github.com/rhalff/dot-object) before passing my obj with values to render: import * as dot from 'dot-object' const vars = dot.object({ Mustache.render("{{PRODUCT.TITLE}} - {{PRODUCT.BRAND}}", obj) |
Was affected by this. Escaping characters is basic behavior guys... How is this not supported? |
Yeah, sadly, I've faced that as well. |
Is this still not considered? |
I know this is closed, but I still wish dedotting was not necessary. If escaping is not the way, what about quoting?
However advanced users could provide their own tokenisers and decide for themselves how to handle various characters. FYI for anyone else, this is currently what I do:
|
It would be really handy for me, and maybe others† if this could be supported. A backend database library I use supports this notation so I end up with objects like this:
I wish I could do something like this in Mustache:
or
It's not that hard to work around, but I thought I'd throw it out there.
† http://stackoverflow.com/questions/14901683/how-do-i-reference-a-field-name-that-contains-a-dot-in-mustache-template
The text was updated successfully, but these errors were encountered: