Closed boris-petrov closed 3 months ago
I think you have to use : {{#items}}
instead of {{#model.items}
.
Also, in order to use expressions such as "model.items" or "$index + 1" you need to enable the angular expressions feature :
https://docxtemplater.com/docs/angular-parse/#setup
Like this :
const expressionParser = require("docxtemplater/expressions.js");
const options = {
parser: expressionParser,
linebreaks: true,
paragraphLoop: true,
delimiters: { start: '{{', end: '}}' },
nullGetter: function () {
return '';
},
};
const doc = new Docxtemplater(zip, options);
doc.render({ items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] });
@edi9999 right, thank you for the answer. Sorry, I've given a wrong reproduction. My use-case is a bit more complex than that and that's why I made a mistake. The real issue is as follows. Change the template to just {{#items}}
as you mentioned (no model
and no $index + 1
). And the important part is to change the JavaScript file to have MORE than 10 items
- so add 11
in the end of the array for example. That breaks. With 10 or less items it works fine. With 11 or more it breaks. Please check it out. That's the real issue.
Can you please make sure to make a reproduction ?
This issue seems very strange and I would like if you could send me the template + the output with 8, 9, 10, and 15 items, in docx format.
Indeed it's very strange, believe me, I spent a few hours today to narrow it down to this template and that data.
That's the right template. This is the code:
const fs = require('fs');
const PizZip = require('pizzip');
const Docxtemplater = require('docxtemplater');
const content = fs.readFileSync("/home/boris/broken.zip", "binary");
const zip = new PizZip(content);
const options = {
linebreaks: true,
paragraphLoop: true,
delimiters: { start: '{{', end: '}}' },
nullGetter: function () {
return '';
},
};
const doc = new Docxtemplater(zip, options);
doc.render({ items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] });
const buf = doc.getZip().generate({type:"nodebuffer"});
fs.writeFileSync("/home/boris/output.docx",buf);
Output with 11: output-11.zip Output with 10: output-10.zip
Note the missing a
, b
and c
. In my real template most of the resulting file was missing. But I guess that's enough for you to debug the issue.
Also, note that pretty much everything in this template is important - the image, the bold .
, the two-line text below it... if any of these things is not exactly like that, it works fine. :smile:
What kind of viewer are you using ? libreoffice, wps, microsoft office on Windows ?
Usually, I try to use different viewers to see if the bug could come from the viewer itself (I've seen bug like that for libreoffice).
See the output here :
Output 10 and output 11 seem very similar (one line of difference).
I see. Yes, I use LibreOffice, but I'll also check on MS Office. Indeed it seems like a bug in the viewer. Thanks for the support!
I have seen bugs like those and opened an issue once (on the libreoffice bug tracker), but I don't think it ever was fixed in libreoffice. The issue was also with tables that sometimes did not show correctly (completely hidden table in some rare cases).
I will try looking for that opened issue and send it here and also ping back libreoffice.
Thanks for your detailed issue.
The issue in libreoffice that I was referring to was : https://bugs.documentfoundation.org/show_bug.cgi?id=155793
But I think yours is a bit different, your issue is about tables changing the way they look, while the issue I was refering to was when you add images in a footer.
I think you could create a new bug on the https://bugs.documentfoundation.org website
Please link the bug here in order to document the issue if you open it :)
https://bugs.documentfoundation.org/show_bug.cgi?id=162537
Thanks for all the help! :)
Thanks :)
Environment
How to reproduce my problem :
My template is the following : broken.zip
With the following js file :
Check the resulting document. It doesn't have the "a", "b" and "c" static texts in the table. Also, the table doesn't have 10 rows with indexes shown. There's something strange going on. Please try it out.