-
Notifications
You must be signed in to change notification settings - Fork 355
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
loops, accessing parents properties #174
Comments
Just write {category}. Explanation : whenever the parser returns undefined, the scope manager will go up to the parent scope. If you write your custom parser, you just have to return undefined if you want to take up to the parent |
thanks it works |
Does this still work with the angular parser? |
Yes, it should also work with angular parser |
You're right, it works. I was running into an issue with filters. It was caused me not returning |
Is there a way to disabling the behavior of looking up in the parent's scope for a particular tag? I expect the answer to be no but it would be a nice feature. |
If you return |
That's a good idea. I created a custom tag syntax inspired by mustache/spec#52. Here's how I achieved it. It's a modification of the custom angular parser. get: tag === '.' ? function(s){ return s;} : function(s) {
// Allow for a preceding . to indicate that scope should be restricted the current scope
// and not travel up the parent scopes. This is achieved by returning '' instead of undefined.
// https://github.com/open-xml-templating/docxtemplater/issues/174
var restrict = false;
if(tag[0] === '.') {
tag = tag.substring(1);
restrict = true;
}
var result = expressions.compile(tag.replace(/’|‘/g, "'"))(s);
if(result === undefined && restrict) {
return '';
} else {
return result;
}
} |
Great ! I would check with |
Hi, is it possible to access parent object properties within a loop.
For example I have
{
"category": "somenthing",
"products":
[
{name:"Windows",price:100},
{name:"Mac OSX",price:200},
{name:"Ubuntu",price:0}
]
}
then in template, can I access "category" somehow?
{#products}
{$parent.category} {name}, {price} €
{/products}
The text was updated successfully, but these errors were encountered: