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
accessing.stuff.with.dots #6
Comments
I'm not sure about this yet - I really like how simple the template system is right now and don't personally have a problem just defining methods for more complicated objects. That way if the object's structure changes it can be caught by your unit tests and only needs to ever be changed in your Ruby code. |
This testing argument caught me too - adding dot syntax would make those views more prone to bugs. |
Great - closing this until it warrants further discussion in the future. |
I am missing something. How do you get back up in a view in the template. Let's say, you need to render user.addressbook.contacts, and after this, you would like to display the user.name. I would you do that? |
{{name}} will go up the stack |
ok, I am not sure I understand how the system work then. Mustache is definitely cool, but not having the "dot" notation is kind of a blocker for us. |
BTW, do not get me wrong, I think mustache.js is very cool, but in our case it pushes the "logicless" a little bit too far. We are settling for jquery-tmpl for now, but we will definitely keep an eye on mustache.js |
There do seem to be a scenario which I cannot figure out how to solve: {{#child}} |
+1, this is exactly what I am confused about. Would love to see the answer. |
You have an object like this: |
So, just that I understand. The solution to access parent values from a {{#child}} element is to duplicate the parent values in the child element. Correct? |
That's the way I would solve you're problem. I'm not saying it's the most DRY use of data. |
For those who can't live without the dot notation (such as myself) here is a branch: http://github.com/mhevery/mustache.js/tree/dot-notation For what it is worth, the dot notation is a must since your data often comes from objects which are structured, and which you don't controll. Flattening them would mean that I would have to write marshaling code, which would mean more code to write and more code to test. Hence, I don't buy the testability argument. |
Here's an example of parent data accessed within a child without dot notation: https://gist.github.com/3c91441597ac650146b9 via: http://librelist.com/browser//mustache/2010/10/16/nested-names/#7f58fcf41fa5a60259932d1efcfb6f60 |
@audionerd thanks for the example. Honestly, I moved to jquery-tmpl. The lack of dot.notation was to much work to work around. It added lot of complexity to rather a simple use case. |
I've moved to jQuery Tmpl also and I'm liking underscore.js also which supports the same syntax: |
What about having a dot notation similar to navigating a directory structure. For example:
Would result in:
Essentially you would provide a dot for each parent conext you want to look at. So, |
Dot notation has been added to Mustache. |
@defunkt where is that? I can see it anywhere. :S |
Seems like the FAQ answer to: |
What is the syntax for dot notation? |
I'm just getting into Mustache and while the missing dots confuse me, I'd rather do without them. I think it force knowledge out of the template and into the view and I like it. It's confusing because t's not what I'm used to with Django, but that's why our project is migrating to mustache - logicless templates that will keep my templates clean and make it possible to get web designers to contribute template code. |
@daonb I think they have added dot support now. However, I am not sure that dot-notation makes the template not as clean. In fact, I am still not convince that the lack of if/else is good either. There is a fine line that you want to draw between what the template needs to do and what need to do before hand (before processing the template). Having to do too much "pre-hashing" before template rendering can make the code more complex that it has to be. |
It would be cool to be able to do {{user.name}} (dot notation access) so it would return user[:name] where user is a method in view returning a Hash. It should also accept statements with more dots like: {{user.address.city}}.
The text was updated successfully, but these errors were encountered: