(Creator of docxtemplater.com here)
Indeed, with the table module (paid module), you can use both horizontal loops {#xx} {/xx} together with vertical loops {:vt# loop} and {:vt/}.
I've just added a section about this in the docs :
https://docxtemplater.com/modules/table/#combining-vertical-and-horizontal-tables
In your case, you would have to transform your data, you could do some from the template itself using an angular filter.
You will need to install angular expressions first which is what we use so that we can create filters such as separateKeys (defined below).
npm install --save angular-expressions
Here would be a fully working example :
const expressionParser = require("docxtemplater/expressions.js");
const doc = new Docxtemplater(zip, {
paragraphLoop: true,
linebreaks: true,
parser: expressionParser.configure({
filters: {
separateKeys(input) {
const keys = Object.keys(input[0]);
// keys wil be ["firstName", "lastName" ]
const res = {
vloop: keys,
values: input.map(function (line) {
return {
vloop: keys.map(function (key) {
return line[key];
}),
};
}),
};
return res;
},
},
}),
});
doc.render({
users: [
{
firstName: "Susan",
lastName: "Storm",
meta: [
{
age: 30,
email: "[email protected]",
},
],
},
{
firstName: "Peter",
lastName: "Parker",
meta: [
{
hairColor: "Brown",
costumeColor: "Red",
},
],
},
],
});
In your template, you would then write (each line is in a table cell, in a table with just one column).
{#users | separateKeys}
(START OF TABLE)
{:vt#vloop}{.}
{-w:tr values}{.}{/}{:vt/}
(END OF TABLE)
{/}
You can download the docx template here :
https://docxtemplater.com/vertical-loop-new-table.docx
In order to properly handle "meta" you would most likely simply have to change the "separateKeys" filter function, or maybe restructure the data first