0

I am using the docxtemplater library to generate a word file. When I use more than 1 tag in the same line, it prompts the following error:

"error":{"name":"TemplateError","message":"Multi error","stack":"Error: Multi error\n    at new XTTemplateError (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\errors.js:24:16)\n
  at throwMultiError (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\errors.js:76:13)\n    at verifyErrors (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\docxtemplater.js:511:5)\n    at Docxtemplater.compile (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\docxtemplater.js:345:7)\n    at new Docxtemplater (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\docxtemplater.js:97:12)\n    at PublicAPI.genMonthlyReport (E:\\Users\\cstsang\\workspace\\coss_sla\\server\\publicAPI.js:29:27)\n    at Layer.handle [as handle_request] (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\express\\lib\\router\\layer.js:95:5)\n    at next (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\express\\lib\\router\\route.js:137:13)\n    at Route.dispatch (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\express\\lib\\router\\route.js:112:3)\n    at Layer.handle [as handle_request] (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\express\\lib\\router\\layer.js:95:5)","properties":{"errors":[{"name":"TemplateError","message":"Unbalanced loop tag","stack":"Error: Unbalanced loop tag\n    at new XTTemplateError (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\errors.js:24:16)\n    at getUnbalancedLoopException (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\errors.js:234:13)\n    at E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\modules\\expand-pair-trait.js:254:21\n    at Array.map (<anonymous>)\n    at Object.postparse (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\modules\\expand-pair-trait.js:213:31)\n    at E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\parser.js:73:24\n    at Array.reduce (<anonymous>)\n    at _postparse (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\parser.js:72:22)\n    at Object.postparse (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\parser.js:94:19)\n    at XmlTemplater.parse (E:\\Users\\cstsang\\workspace\\coss_sla\\node_modules\\docxtemplater\\js\\xml-templater.js:172:38)","properties":{"id":"unbalanced_loop_tags","explanation":"Unbalanced loop tags {#actionTypeSummary}{/actionTypeSummary}{#abc}{/abc}","offset":[2575,2640],"lastPair":{"left":"actionTypeSummary","right":"actionTypeSummary"},"pair":{"left":"abc","right":"abc"},"file":"word/document.xml"}}],"id":"multi_error","explanation":"The template has multiple errors"}}}

The below image shows the word file template situation for your reference.

enter image description here

When I remove all {abc} tags, it works fine.

The code fragment of publicAPI.js as below:

let content = fs.readFileSync(path.resolve(__dirname, 'template.docx'), 'binary');
let zip = new PizZip(content);
let doc = new Docxtemplater(zip, { paragraphLoop: true, linebreaks: true }); 

The statement let doc = new Docxtemplater(zip, { paragraphLoop: true, linebreaks: true }); is line 29 of publicAPI.js

edi9999
  • 19,701
  • 13
  • 88
  • 127
The KNVB
  • 3,588
  • 3
  • 29
  • 54

1 Answers1

0

After I search the keyword "Unbalanced loop tag", from the web page, I found the solution, the template should be as the following:

enter image description here

The KNVB
  • 3,588
  • 3
  • 29
  • 54