Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
947 lines (565 sloc) 26 KB


Make docxtemplater fail with following error messages when using the v4 constructor with either setOptions or attachModule :

  • setOptions() should not be called manually when using the v4 constructor
  • attachModule() should not be called manually when using the v4 constructor

You should not write :

const doc = new Docxtemplater(zip);
    delimiters: {
      start: "<",
      end: ">",
doc.attachModule(new ImageModule())

You should instead write :

const doc = new Docxtemplater(zip, {
	modules: [new ImageModule()],
    delimiters: {
      start: "<",
      end: ">",


  • Update moduleApiVersion to 3.23.0.
  • Add contentType property in options passed to parse, postparse, render and postrender.
  • Bugfix in apiversion check, the patch version was not taken into account at all previously


Add proofstate module to allow to remove the <w:proofState w:grammar="clean" w:spelling="clean"/> tag during .render()


  • Add support for automatically detaching modules that do not support the current filetype when using constructor v4. In previous versions, you would do the following:
let doc = new Docxtemplater();
const zip = new PizZip(buffer)

if (doc.fileType === "pptx") {
    doc.attachModule(new SlidesModule());

Now it is possible to write the following, without needing the condition on filetype:

const zip = new PizZip(buffer)
const options = {
    modules: [new SlidesModule()],
try {
   const doc = new Docxtemplater(zip, options);
catch (e) {
    // error handler
  • Update moduleApiVersion to 3.22.0.


  • Add a constructor method that accepts zip and optionally modules and other options. This constructor will be the official constructor in docxtemplater v4 and the methods: loadZip, attachModule, setOptions and compile will no more be available.

You can migrate the following code:

const doc = new Docxtemplater();
    delimiters: {
      start: "<",
      end: ">",
doc.attachModule(new ImageModule())
doc.attachModule(new Htmlmodule())
doc.attachModule(new Pptxmodule())
try {
catch (e) {
     // error handler


const options = {
    modules: [new ImageModule(), new Htmlmodule(), new Pptxmodule()],
    delimiters: {
      start: "<",
      end: ">",
try {
   const doc = new Docxtemplater(zip, options);
catch (e) {
     // error handler
  • This change is backward compatible, meaning that you can continue to use the constructor with no arguments for the time being.


  • Add specific error (Duplicate open tag and Duplicate close tag) when using {{foobar}} in a template when the delimiters are just one single { and }
  • Avoid error TypeError: Cannot set property 'file' of undefined that hides the real error


  • Properly decode &amp;gt; into &gt; in templates, in previous versions, the value was decoded to >


  • Pass in {match, getValue, getValues} functions to second argument of module.parse
  • Allow to have a promise at the root level in resolveData
  • Update moduleApiVersion to 3.21.0


(Internal, for modules) Pass whole part instead of just part.value to explanation function


Bugfix with paragraphLoops containing pagebreaks + tables, the pagebreak got reordered


Bugfix corrupt document when using dashloop : {-a:p loop} inside table cell which renders false


Other bugfixes related to pagebreaks and loops


Bugfix issue with paragraphLoop and pagebreaks.

In some situations, the pagebreak got removed if the start of the loop is at the top of the page (right after the w:br element).


  • Add options.lIndex and other information about the current token in the module.parse method.
  • Update moduleApiVersion to 3.20.0


Since this version, modules using the expandToOne trait will be able to throw a specific error instead of the one related to the raw-xml module, ("Raw tag not in paragraph")


Bugfix for loop module contained inside grid slides module : Do not fail with error "Unopened loop"


Bugfix for loop module and raw module : when having an "execution" error in the parser (eg on render, after the compilation of the template, for example with the angular parser when a filter is called with bad arguments), if one {#looptag} or {@rawtag} had an execution error, the code would immediately stop collecting other errors. Now docxtemplater will collect all errors, for simple tags, for loop tags, and for rawxml tags.

This means that if your template was like this :


Before version 3.16.0, calling render on this template would throw an error with just the first tag erroring.

Since version 3.16.0, a multi error is thrown with all three tags in error being in .properties.errors.

This is fixed in sync mode (when calling doc.render directly) and also in async mode (when calling doc.resolveData and then doc.render)


  • Add scopePathLength to scopemanager to be able to write "$isLast".
  • Update moduleApiVersion to 3.19.0


Add offset property to following errors :

"No w:p was found at the left"
"No w:p was found at the right"


Bugfix when having dashloop inside normal loop, like this :

{#foo}test {-w:p loop}loop{/}{/}

we now throw a multi error instead of just the first error encountered.


  • Update moduleApiVersion to 3.18.0
  • (internal) Use array of string for shouldContain to fix corruptions
  • Do not add <w:p> in <w:sdtContent> if it contains a <w:r>


  • If you use the xlsx module, please update the xlsx module to 3.1.1 or you will get a stacktrace Cannot set property 'parse' of undefined
  • Update moduleApiVersion to 3.17.0
  • Add options.parse function in parse(placeholder, options) to allow "recursive" parsing
  • Fill empty <w:sdtContent> with <w:p> to avoid corruption


  • Update moduleApiVersion to 3.16.0
  • Disallow to call attachModule twice on a given module
  • Add options to parse and postparse such as filePath


Use {} (empty object) instead of "false" for the fs shim in the browser.


  • Bugfix for joinUncorrupt method, which produced a corrupt document when having a paragraphLoop containing a table containing a {-w:tr loop} loop.


  • Update moduleApiVersion to 3.15.0

  • Add joinUncorrupt to options in module.render to be able to fix corruptions

  • Fixes corruption when using {#loops} that contain tables with {@rawXML} evaluating to empty.


  • Add p:txBody to pptx-lexed to handle corruption on pptx


  • Update moduleApiVersion to 3.14.0

  • Add getNearestLeftIndex, getNearestRightIndex, getNearestLeftIndexWithCache, getNearestRightIndexWithCache to doc-utils.

  • Add preparse method to modules to be able to retrieve info about document before the parsing of the whole document by other modules.

  • Add tagShouldContain to the filetype API to be able to make the documents valid, which would make it possible to remove the part.emptyValue trick.


Bugfix when using paragraphLoop section with a pagebreak : at the end of the paragraphLoop, the pagebreak was removed by mistake. This is no longer the case since this version


Bugfix speed issue when having many loop tags in the same paragraph (over 50 loop tags in one paragraph).

(internal) Update verify moduleAPI to 3.13.0 (addition of getNearestLeftWithCache, getNearestRightWithCache, buildNearestCache)


Throw Error with offsets when having loop start tag inside table and loop end tag outside table


Update xmlprettify and test it

Update dependencies


Add support for .docm format


Document the usage of PizZip instead of JSZip


Improved fix for 3.13.5, to still create a scope but that is the same as the parent scope (without deep copy)


Bugfix condition when value is truthy, the subscope was incorrect

(This is a fix on top of 3.13.3, which fixed a bug for the value true but not for other truthy values such as integers, strings).


Fix support for Node 6 (also for Nashorn): Rebuild js after upgrade to latest babel version


Bugfix condition when value is === true, the subscope was incorrect


Auto verify moduleAPI version on attachModule


Fix undefined is not a function evaluating 'object.getOwnPropertyDescriptors', by downgrading to babel 7.4


  • Throw multi Error with offsets when having rendering error (makes it possible to use the error location module on rendering errors).

  • Avoid false positive error "The filetype for this file could not be identified" when the document uses <Default> in the [Content_Types].xml file

  • Add getFileType module API to add potential support for other filetypes


Add support for setting the same delimiter on the start and beginning, for example :

%user%, by doing doc.setOptions({delimiters: {start: "%", end: "%"}});

Remove (internal) scopeManager.clone, which is no more used


Add offset property to unopened/unclosed loop error


Parse selfclosing tag correctly, such as in <w:rPr><w:noProof/></w:rPr>


  • Bugfix issue with conditions in async mode conflicting sometimes

For example with the template :


and the data :

	label: "outer",
	loop: [
			cond2: true,
			label: "inner",

The label would render as outer even though it should render as inner.


  • Bugfix speed issue introduced in 3.10.0 for rawXmlModule


  • Bugfix corruption when using paragraphLoop with a template containing <w:p> as direct childs of other <w:p>.

  • Update getLeft, getRight, getNearestLeft, getNearestRight, getLeftOrNull, getRightOrNull to take into account the nesting of tags.

  • Ensure that the f functor is always called when using chunkBy (like the native .map function)

  • In expandOne trait, call getLeft before getRight


  • Improve detection of filetype to read information directly from [Content_Types].xml instead of from zip files.


  • WIPED - Published by mistake.


  • Add support for multiple elements in getRightOrNull and getLeftOrNull (to be able to specify array of elements in traits.expandToOne

  • Add postparse to expandToOne


  • Add index and prefix property to render method in the second argument ( options.prefix and options.render )

  • Make sure that postrender returns an array of the same length as it gets

  • Update moduleApiVersion to 3.9.0


  • Update moduleApiVersion to 3.8.0


When using a paragraphLoop inside a table like this :

{#loop} Content {/loop}

When loop was falsey, the table cell caused a corruption in the resulting document.

This now fixes the issue, an empty "<w:p>/w:p" is insereted.


Performance fix in inspectModule. This performance fix concerns you only if you do doc.attachModule(inspectModule).

On some templates, and when reusing the same inspectModule instance, the rendering could be very slow (20 minutes in some cases). On a simple test case, the rendering time has decreased from 6 seconds to 90ms.


Render all spaces when using linebreak option


Remove .babelrc from published module


Expose Lexer to modules (API Version 3-7-0)


Fix issue with nested loops with paragraphLoop :


would produce No tag "w:p" was found at the left

It now renders the same way as without paragraphLoop


  • Add possibility to change the prefix of the rawxmlmodule and of the loopmodule

  • In parsed output, also add raw containing the full tag, for example {#loop} will be parsed to : {value: "loop", raw: "#loop"}


Fix bug with {linebreaks: true} throwing a.split is not a function


Add templating of more meta data of the document, including :

Author, Title, Topic, marks, Categories, Comments, Company


Fix bug with resolveData algorithm, which raised the error : "Cannot read property value of undefined" in the render call.


Fix bug wrong styling when using linebreaks.


  • Add linebreaks option for pptx and docx


Revert : Add back lIndex to parsed in addition to endLindex : Fixes issue with async rendering of multiple tags (images, qrcode, ...)


  • Add nullGetter module API

  • Update inspectModule to have :

    • Unused variables (nullValues)
    • filetype
    • data from setData()
    • templatedFiles
    • list of tags


In firefox, fix : Argument 1 of DOMParser.constructor does not implement interface Principal


Fix issue of remaining xmlns="" in some docx files


Fix issue with loopmodule eating up whitespace characters


Allow to set delimiters to {start: '<', end: '>'} #403


Add meta context argument to custom parser with information about the tag for each types of tags


Fix infinite loop when XML is invalid (throw an explicit error instead)



Fix : Add more information to context in the parser to be able to write {#users}{$index} - {name}.

See for full doc.


Add scopeManager argument to nullGetter to know what variable is undefined.



  • Fix #226 when using {@rawXml} tag inside table column, the document is no longer corrupted


  • Use JSZipUtils in tests


  • Add resolveData function for async data resolving

  • Fix bugs with spacing : Now space="preserve" is applied in the first and last <w:t> of each placeholder


  • Update getAllTags to work with multiple loops by merging fields.


  • Add getAllTags to inspectModule

  • Add base-modules after loadZip instead of on compile


Breaking change : The syntax of change delimiter has been changed from :

{=<% %>}


{=<% %>=}

To change to <% and %> delimiters.

The reason is that this allows to parse the delimiters without any assumption.

For example {={{ }}} was not possible to parse at version 3.4.0, but by adding the ending equal sign : {={{ }}=}, the ambiguity is removed.


Add change delimiter syntax from inside template :

For example :

* {default_tags}
{=<% %>}
* <% erb_style_tags %>
<%={ }%>
* { default_tags_again }
  • Add getTags to InspectModule.


  • Automatically strip empty namespaces in xml files

  • Do not throw postparsed errors for tags that are unclosed/unopened


Throw error if the output contains invalid XML characters


Take into account paragraphLoop for PPTX documents


Correctly replace titles of PPTX documents


Add support for Office365 generated documents (with word/document2.xml file)


  • Fix rendering issues with paragraphLoop

When setting paragraphLoop, the intention is to have a special case for loops when you write :


Eg : both the start of the loop and the end of the loop are in a paragraph, surrounded by no other content. In that particular case, we render the content of the loop ({name}) in this use case, in a new paragraph each time, so that there would be no additional whitespace added to the loop.

On version 3.2.1, the paragraphLoop would change the rendering for most of the loops, for example, if you wrote :

My paragraph {#users}

the paragraphLoop code was triggered, and if users was [], even the text "My paragraph" would be removed, which was a bug.

This release fixes that bug.


  • Fix bug with tr loop inside paragraphLoop

If doing

| {#row} |  {/row}   |

An unexpected error 'No "w:tr" found at the left' would be raised.


Add paragraphLoop option, that permits to have better rendering for spaces (Fixes #272)

It is recommended to turn that option on, because the templates are more readable. However since it breaks backwards-compatibility, it is turned off by default.


Inspect postparsed in compile() method instead of render()


  • Add support for self-closing tag in xmlMatcher -
  • Add tag information in parsed/postparsed


  • Review testing code to always use "real" docx


  • Add support for setting the prefix when attaching a module.
  • Bugfix when looping over selfclosing tag


Add error loop_position_invalid when the position of the loop would produce invalid xml (for example, when putting the start of a loop in a table and the end outside the loop


Use createFolders JSZip option to avoid docx corruption


Show clear error if file is ODT, escape " as &quot;


Template values in docProps/core.xml and docProps/app.xml


Add possibility to have RenderingErrors (if data is incorrect)


Fix RangeError: Maximum call stack size exceeded with very big document


Handle unclosed tag <a:t /> and <w:t />


Bugfix loop over string value (fixes\)


Add support for multi errors :

docxtemplater doesn't fail on the first error, but instead, will throw multiple errors at the time. See for a detailled explanation.


Add js/tests to npm package (for modules)


Reduce size of the package


Reduce size of the package


Reduce size of the package (718.9 MB to 1.0 MB), and add prepublish script to ensure the size will never exceed 1.5MB


Add expanded property when using expandTo


Bugfix : Do not decode utf8 in xmlDocuments


  • When using getRenderedMap in the modules, we now pass the filepath of the file that will be generated instead of the path of the template.


  • Remove cycle between traits and docutils
  • Make sure fileTypeConfig is uptodate


  • Autodetection of filetype : if you use pptx, you don't have to write doc.setOptions({fileType: "pptx"}) anymore.

  • Intelligent tagging for pptx (Fixes issue #284)


  • Update documentation
  • Completely remove intelligentTagging (which is on for everyone)
  • Performance improvements for arrays: prefer push over concat
  • Add automatic module wrapping
  • Add mecanism to change which files to template with modules


3.0.1 [YANKED]

This release was published by error, and should not be used at all.


  • The rendering of the templates has now multiple steps : Lexing, Parsing, and Rendering. This makes the code much more robust, they might be bugs at the beginning, but in the long run, the code is much easier to understand/debug/change.

  • The module system was completely changed, no compatibility is kept between version 2 and version 3, please make sure to update your modules if needed.

  • You can't have the same startTag and endTag (for example $foo$), because this would make the code more complex and the errorHandling quite impossible.

  • All extended features (loop, rawxml, invertedloops), are written as v3 modules. We dogfood our own module system, and will hopefully improve it that way.

  • The constructor arguments have been removed, and you are responsible to load the JSZip.

    Instead of :

    var doc = new Docxtemplater(content);

    You now should do :

    var zip = new JSZip(content);
    var doc=new Docxtemplater().loadZip(zip)
  • getTags() has been removed. It is now not easily possible to get the tags. See for a alternate solution

The JSZip version that you use should be 2.x, the 3.x is now exclusively async, which Docxtemplater doesn't handle yet.


  • Fix stacktrace not showing up (#245)


  • Fixed a memory leak when using large document (10Mb document.xml) (#237)
  • Add fileTypeConfig options in setOptions to define your own fileType config (#235)


  • {@rawXml} has been fixed for pptx


  • Add possibility to close loopTag with {/} #192


  • Bug fix : Some times, docxtemplater could eat lots of memory due to the new "compilation" feature that was only experimental. As this feature is not yet used, it was completely removed from the codebase.
  • Performance : The code has been made a little bit faster.


  • Speed Improvements : docxtemplater had a regression causing it to be slow for loops. The regression would cause the code to run in O(n²) instead of O(n) where n is the length of the loops (with {#users}{name}{/users}. The bug is now fixed, and docxtemplater gained a lot of speed for users of lengthy loops.


  • Breaking : To choose between docx or pptx, you now have to pass docx.setOptions({fileType:'docx'}) where the fileTypes are one of 'pptx', 'docx' (default is 'docx')
  • Using es6 instead of coffeescript to code (code is still compiled to es5, to be usable with node v0.{10,12} or in the browser)
  • Add finalize step in render function to throw an error if a tag is unclosed
  • Module API has been updated, notably the tagXml property doesn't exist anymore, you should use the properties in fileTypeConfig
  • You should check if your modules have updated for the new module API, for instance, you should use version 1.0 of the docxtemplater image module

For example :

var xmlTemplater = this.manager.getInstance("xmlTemplater");
var tagXml = xmlTemplater.fileTypeConfig.tagsXmlArray[0];


  • It is now possible to use tags inside of docx equations


  • This release adds error management, all errors that are thrown by docxtemplater are now typed and contain additional properties.


  • fix : When using loops with images inside, the modulemanager was not updated and would continue to return 'image' for the type of the tag even if the type changed


  • feature : it is now possible to set the nullgetter for simple tags and for raw xml tags.


  • bugfix for the modulemanager : it was not in sync in some cases


  • They now is a default value for rawtags {@rawXml}, which is '' (this will delete the paragraph)


  • bugfix (There was still '{' and '}' hardcoded)


  • It is now possible to output the delimiters in the output (for example output "Mark } Z" with the template {name}
  • scopeManager now doesn't return the string 'undefined' when the parser returns null. That behaviour is moved to the xmlTemplater class


  • docxtemplater is now much faster to process loops #131
  • docutils should not be used any more except for DocUtils.defaults (eg docutils is deprecated)
  • Module maintainers: please don't rely on docUtils anymore, except for docUtils.defaults
  • Some templates would output corrupt templates, this should not happen anymore (if it still does, please open an issue)

Upgrade guide :

  • If you use modules (image-module, chart-module, or others) its best to update those because they shouldn't use DocUtils anymore


  • Add ScopeManager.loopOverValue


  • {@rawXml} works in pptx
  • Created new website
  • Using mocha instead of jasmine-node
  • New FAQ section in docs


  • Corrupt documents when <w:t>}{/body}</w:t>


  • New events for moduleManager : xmlRendering and xmlRendered


  • pptx generation was repaired 2be10b69d47e8c4ba0f541e4d201b29ef6281505
  • header generation works with any amount of headers/footers
  • slide generation works with any amount of slides


  • docx.setOptions({delimiters:{start:”[“,end:”]”}}) now works e2d06dedd88860d2dac3d598b590bf81e2d113a6


  • allowing same tag as start and end delimiter (eg @user@ instead of {user}) 32b9a7645f659ae835fd695e4d8ea99cc6bbec94


  • made it possible to use objects to loop over (eg {#user} {name} {/user}) 97411cb3537be08f48ff707ac34d6aac8b008c50

From 0.7.x to 1

  • docxtemplater doesn’t depend on fs anymore, for transparency and security reasons.
  • loadFromFile has been removed. You now just have to pass the content to Docxtemplater’s constructor.
  • setTags has been renamed to setData
  • applyTags has been renamed to render
  • the constructor has changed: eg new Docxtemplater(content,options) will now call JSzip.load(content,options).
  • To pass options (such as the parser), you will have to call setOptions
  • The output function has been removed. You should now call getZip().generate(options) where the options are documented here:
  • the qrcode module has been removed, and will be developped in an other package that will be attached to docxtemplater

From 0.6.0 to 0.7.0

The QrCode Option had a security issue. If you don’t upgrade according to this, the functionality should continue to work but the leak will still be there. If you are running in the browser, the vulnerability will not affect you (no access to the filesystem). If the users can’t change the qrCodes or their value, you’re safe too.

If you set qrCode:true, you are affected. The Command Line is not affected as of v0.7.0 (but was on 0.6.3 and less). However the command line as of v0.7.0 is not more able to load images over the filesystem.

You should set qrCode to a function now, according to

You can’t perform that action at this time.