Skip to content
Gallery
Export to Word Pro User Guide
Share
Explore
Setup Guide

icon picker
Template Building Guide

NOTE: This pack uses the docxtemplater library to implement the tag replacement. For additional info + examples on building templates, see their .

Types of Tags

1. Placeholders

Usage in Template Doc

{tagName}

GenerateWordDoc( ) Usage

GenerateWordDoc(template.docx, "My Document", "tagName", [string])
where [string] is any text value

GenerateDocFromJSON( ) Usage

GenerateDocFromJSON(template.docx, "My Document", "{"tagName":"[value]"}")
where [value] is any text value

2. Conditionals

Usage in Template Doc

{#tagName}Show this sentence.{/tagName}

GenerateWordDoc( ) Usage

GenerateWordDoc(template.docx, "My Document", "tagName", [boolean])
where [boolean] is either true() or false()

GenerateDocFromJSON( ) Usage

GenerateDocFromJSON(template.docx, "My Document", "{"tagName":[boolean]}")
where [boolean] is either true or false

3. Loops

Usage in Template Doc

{#loopTag}
Inner loop text. {innerLoopVariable}
{/loopTag}

GenerateWordDoc( ) Usage

N/A (can’t be used for loops)

GenerateDocFromJSON( ) Usage

GenerateDocFromJSON(template.docx, "My Document", "{"loopTag":[{"innerLoopVariable": "[value1]"}, {"innerLoopVariable": "[value2]"}, {"innerLoopVariable": "[value3]"}]}")
where [value1], [value2], and [value3] are any text values

Examples

1. Without Loops

Template Doc

Below is a template doc that uses one placeholder tag (name) and one conditional tag (showPara).

Input Data

The data we want to use in this template is below:
Name
Show Paragraph
1
Tommy
There are no rows in this table

Button Formula

We will use the GenerateWordDoc formula since we don’t need loops. The button setup should look like this:
image.png

Try It!

Click the “Generate Word Doc” button to generate the filled-in word doc and then click the Download Link to save and view it. Try changing the values in the table to see how the exported Word Docs change.
Generate Word Doc
Download Link (expires after 15min)
1
Generate Word Doc
There are no rows in this table

2. With Loops

Template Doc

Input Data

Name
Show Paragraph
Vegetables
1
Sandy
Carrots
Cucumber
Tomatoes
There are no rows in this table

Button Formula

We will use the GenerateDocFromJSON formula since we need loops this time. There are a few ways to generate JSON in Coda. Whichever method you use, you will need to end up with a JSON string that looks like this for the template doc and input data above:
{"name":"Sandy","showPara":true,"veggieList":[{"vegetable":"Carrots"},{"vegetable":"Cucumber"},{"vegetable":"Tomatoes"}]}

For this example, we’ve used the JSONify() and ListToText() formulas that are supplied in the Export to Word Pro pack to build the JSON. The complete formula looks like this:
image.png
The button setup for using the GenerateDocFromJSON() formula should look like this:
image.png

Try It!

Click the “Generate Word Doc” button to generate the filled-in word doc and then click the Download Link to save and view it. Try changing the values in the table to see how the JSON and the exported Word Docs change.
Generate Word Doc
Download Link (expires after 15min)
JSON
1
Generate Word Doc
{"name":"Sandy","showPara":true,"veggieList":[{"vegetable":"Carrots"},{"vegetable":"Cucumber"},{"vegetable":"Tomatoes"}]}
There are no rows in this table


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.