Demo Readme Changelog Buy subtemplate module

Summary (version 3.1.7)

This module adds a tag to include the content of an other docx document (which can be a template itself). This allows you to define subtemplates if your templates share common parts.

This module is available as part of the docxtemplater PRO plan.

Demo

Input Output
Data Code
{
    "header": headerDoc,
    "footer": footerDoc
}
const headerDoc = new Docxtemplater().loadZip(new JSZip(headerZip))
const footerDoc = new Docxtemplater().loadZip(new JSZip(footerZip))

const doc = new Docxtemplater();
const inputZip = new JSZip(docX);
doc.loadZip(inputZip)
	.setData({
		header: headerDoc,
		footer: footerDoc,
	});
const subtemplateModule = new SubtemplateModule();
doc.attachModule(subtemplateModule);
const output = doc.render().getZip();

README

Subtemplate Module

This module exposes a tag to include subtemplate. The subtemplate is embeded into your document. Only the document content is embedded, footers and headers are not since they are unique for each document, so we use the headers/footers from your base template.

Installation:

You will need docxtemplater v3: npm install docxtemplater

Install this module with npm install --save "$url"

Usage

Your docx should contain the text: {:include subtemplate}. You can find a working sample at ./sample.js

Building

You can build the es6 into js by running npm run compile

Testing

npm test

CHANGELOG

3.1.7

Add support for including documents containing charts

3.1.6

Remove error getElementsByTagName when word/numbering.xml doesn't exist in main document

3.1.5

Fix bug when subtemplate contains list coming from an other module (HTML)

3.1.4

Images in the subtemplate when there are already some images in the headers does not cause a corruption anymore.

3.1.3

Links in the subtemplate are now handled correctly

3.1.2

Fix corruption on some word version because of duplicate styles

3.1.1

Add support for lists in subtemplates (ordered lists and unordered lists).

3.1.0

Import styles in the case when the included document defines some styles.

3.0.1

Handle images importing

3.0.0

Initial release

Edgar Hipp

I'm the creator of docxtemplater. I work on making docxtemplater great since 2013.