Nested conditions
Kolis121 opened this issue · 4 comments
- Version of docxtemplater : 3.37.2
- Used docxtemplater-modules : Free module
- Runner : TypeScript
How to reproduce my problem :
If we have nested conditions, I realized, in the example below, the last condition is not executed at all.
{#users.length > 3}
There are many users
{#users.length > 3}
{#users.length > 3}
{#usersxxxx}
{name1}
{name2}
{#users.length > 3}
....
Hello @Kolis121 ,
Can you please send me your template (in docx format), data + code so that I can reproduce the issue.
It seems that your loops are never closed in your sample.
I'm closing this since there's not much I can do without more information.
Sorry, I got stuck with some other stuff...
Please find attached the Word file I tested back then.
I just wanted to replicate this issue to be sure, but I realized I have another error "Error: Scope parser execution failed" - I used the ExpressionParser you used in #717. I guess this Expression Parser you used cannot handle the conditions in the tag.
Are you using following code :
const expressionParser = require("docxtemplater/expressions-ie11.js");
const doc = new Docxtemplater(zip, { parser: function(tag) {
return {
get: function(scope, context) {
const result = expressionParser(tag).get(scope, context);
return result;
}
}
}});
doc.render(tags);
If yes, please make sure that you are using the latest docxtemplater (3.37.8)
If this still happens, please try the following and report back the new logs :
const expressionParser = require("docxtemplater/expressions-ie11.js");
const doc = new Docxtemplater(zip, {
parser: function(tag) {
return {
get (scope, context) {
try {
const result = expressionParser(tag).get(scope, context);
return result;
} catch (e) {
console.log(e.message);
console.log(e.stack);
throw e;
}
},
};
},
});
doc.render(tags);