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
loop rendering bug - inner loop props are rendered with root level data #523
Comments
BTW, I currently deal with it using a custom parser:
But I am not sure I'm not breaking anything else... |
Hello @shaharsol , I've just added it to the FAQ. If you use the following condition it should work :
|
I think your condition will also work, it is just a bit more specific. With my condition, it will work regardless of the "nesting", eg it will never use a scope that is not the "deepest one". With your condition, it will return null only when doing the last evaluation on the rootScope, but it won't circuit-break if having 2 levels of loops. |
@edi9999 thanks for your quick response. However, don't you think it's a bug? Is this the intended behavior? This "scope inheritance" is actually thought of? |
No, I don't think it is a bug, most users expect that the upper scope can be accessed from within a loop. Docxtemplater is inspired by mustache and I think in most mustache implementation, it works like this (altough I'm not sure whether it is specified explicitly). See janl/mustache.js#399 for a discussion. Docxtemplater is actually less strict then that, since, with the custom parser, it allows you to change the behavior. |
Environment
How to reproduce my problem :
My template is the following :
template.zip
With the following js file :
This is the result:
ret.zip
The problem is that the
name
property, which is set in the root data element, is rendered as if it was part ofproducts
. I would expect it not to render there, and let thenullGetter
handle that value since it supposed to be null.The text was updated successfully, but these errors were encountered: