1. Tasks
  2. Docx Templating

Tasks

Docx Templating

Replaces placeholders in a Word (`.docx`) template with values from JSON data, generating a personalized document.

Basic usage

loading...

Parameters

doc_templates
required
objects

The parameters for the docx template files

Show child attributes
files
optional
array

Contains the docx template file(s) which contain placeholders to be replaced.

fileuuids
optional
array

The fileuuids of docx template file(s) which contain placeholders to be replaced.


settings
required
object

The settings for the task

Show child attributes
set_filename
required
string

The name of the output file. .docx will automatically be appended to the output file's name. If there are multiple template files, the filenames will be the same with a number appended to the end of it to indicate its index.


compile_data
required
object

The JSON object containing the data to replace the placeholders in the template file(s).


Result

loading...

Properties

compiled_files

An array containing all the fileuuid(s) and filename(s) of template(s) that have been compiled.

Examples

Basic Usage

This example will show you how to set up a basic template to be compiled.

Place placeholders in the format {{placeholder_path}} in your document. The placeholder_path is the path in the JSON data from which the value is found to replace the placeholder.

The image below contains an example of a section of a template document.

The compile_data can then be as follows:

loading...

The task will replace the placeholders with the data in compile_data resulting in the outputted docx document to look as follows:

Notice how the final Bob is capitalised, this is due to the upper in the template document. Using upper or lower in a placeholder after the placeholder JSON location and | divider, will make the value uppercase and lowercase respectively. For example: {{person.first_name | upper}} or {{person.first_name | lower}}

Loops and Tables

This example will show you how to create a table by looping over an array in compile_data.

In order to loop through an array create the placeholder as follows: {{#array_name}} {{key_in_array}} {{/array_name}}. The image below contains an example of a table in a template document:

Take note that the placeholders within the loop do not contain the entire hierarchy. When looping declare the loop with {{#array_name}} and this will automatically be added to the values in the loop e.g: {{quantity}} is actually items.quantity but because it is within a loop, the upper level hierachies are not required and quantity is written without items

The compile_data for this example is:

loading...

The outputted document will contain the following: