-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
../myVar should reference the rootContext #48
Comments
* ../myVar should reference the rootContext #48 * ../ point to the parent context
Just one comment Thanks, Marc. |
Are you sure about that? From the discussions I saw, ../ refers to the root template. |
Yes, I'm sure. {
"foo": {
"bar": {
"title": "bar"
},
"title": "foo"
},
"title": "root"
} with:
The output is: with:
output is: with:
output is: with:
output is: You can try all these here: http://tryhandlebarsjs.com/ |
Hmm, the interesting question then also becomes: how to reference a global variable (such as serverUrl) when you can't predict at which level a partial is included |
I found something weird. When I started with handlebars I was under the assumption that Handlebars.js was a Mustache complaint implementation. Now, in Mustache if a value isn't found in the current scope, that value is resolved against the context stack, i.e., it looks in the parent until the value if found or until the root context is reach. So, you can safely refer to The following example is part of the Mustache Spec. It works in handlebars.java but not in handlebars.js {a: {one: 1}, b: {two: 2}, c: {three: 3}, d: {four: 4}, e: {five: 5}} Template: {{#a}}
{{one}}
{{#b}}
{{one}}{{two}}{{one}}
{{#c}}
{{one}}{{two}}{{three}}{{two}}{{one}}
{{#d}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{#e}}
{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
{{/e}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{/d}}
{{one}}{{two}}{{three}}{{two}}{{one}}
{{/c}}
{{one}}{{two}}{{one}}
{{/b}}
{{one}}
{{/a}} Output:
|
The .combine(someContext) allows me access to some global scoped variables. However, in order to maintain compatibility with my Javascript version, I need to be able use Handlebars Paths to be able to reference the root scope.
The Handlebars documentation references Paths as a way to reference the root scope (it's not entirely clear if it should be parent or root scope, but root scope would make the most sense).
Right now using {{../myVar}} throws an error. It should either display the variable or nothing from within a partial.
The text was updated successfully, but these errors were encountered: