Replies: 3 comments
-
|
Hello @jviseur! In principle, rendering the same data against multiple templates should be doable with a Merge node set to Combine by All Possible Combinations. Something like this:
The Merge node should be set up like this:
Then, you need to ensure that the branch that generates the templates, e.g. from Google Drive or from Read from Disk or from HTTP Requests or from FTP or whatever, generates multiple items, each with a Binary property. The other branch should contain the JSON document that you'll use as context (or you could just write it directly on the DocxTemplater node, in the Data field) Combine+All Possible Combinations will multiply the N items with binary data by the 1 item with JSON data, and the result will be N×1=N items with both JSON and binary data. Those can then be passed as normal to the DocxTemplater node, it'll automatically (like almost all N8N nodes) run once for each of the items that it's passed. As for compressing all those output items into a single one, you could handle it like discussed here. You need to add a Code node that converts all the items, each with a {
"nodes": [
{
"parameters": {
"jsCode": "let binaries = {}, binary_keys = [];\n\nfor (const [index, inputItem] of Object.entries($input.all())) {\n binaries[`data_${index}`] = inputItem.binary.data;\n binary_keys.push(`data_${index}`);\n}\n\nreturn [{\n json: {\n binary_keys: binary_keys.join(',')\n },\n binary: binaries\n}];\n"
},
"name": "Merge items",
"type": "n8n-nodes-base.code",
"position": [
432,
584
],
"typeVersion": 1
}
],
"connections": {
"Merge items": {
"main": [
[]
]
}
}
}This node will work like this:
It receives multiple items, each with the same binary property (here it's Then, you can add a Compression node like this one: {
"nodes": [
{
"parameters": {
"operation": "compress",
"binaryPropertyName": "={{ $binary.keys().join(\",\") }}",
"fileName": "docs.zip"
},
"type": "n8n-nodes-base.compression",
"typeVersion": 1.1,
"position": [
656,
584
],
"name": "Compression"
}
],
"connections": {}
}
The trick in that node is that the Input Binary Fields setting is set to Let me know if this works or if you encounter any errors |
Beta Was this translation helpful? Give feedback.
-
|
@jreyesr thank you for your answer |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.





Uh oh!
There was an error while loading. Please reload this page.
-
I have a need where I need to create a set of document using the same data source but each document has it's own template.
Is there a way that can be done using n8n and DocxTemplater?
One option is to call the Workflow as many times as there are templates and then manually zip the documents. Is there an option to feed all templates and generate the documents and then zip them?
Beta Was this translation helpful? Give feedback.
All reactions