Expression Parser with customized parser function
Kolis121 opened this issue · 1 comments
Kolis121 commented
- Version of docxtemplater : 3.37.2
- Used docxtemplater-modules : Free module
- Runner : TypeScript
How to reproduce my problem :
I have error The scope parser for the tag "users" failed to compile
when I have condition expressions in the document.
The point is if I follow the manual below where for parser we only have this: parser: expressionParser
, it is OK I think.
https://docxtemplater.com/docs/angular-parse/
But what if I have a customized parser function like this and I also want to use the expressionParser?
parser:
function(tag: string) {
(( - my function content - ))
},
I tried the below, but it does not work.
parser:
[
function(tag: string) {
(( - my function content - ))
},
expressionParser,
],
edi9999 commented
You can do something like this :
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);