Template Syntax
Simple Text Replacement
To insert text in your template, use double curly braces with a tag name:
When you generate a document from the template, this tag will be replaced with the corresponding value from your data. For example:
{
"FirstName": "John"
}
The tag {{ FirstName }}
will be replaced with "John" while preserving any text
formatting (bold, italic, font size, etc.) applied to the tag in the original Word
document.
Loops
To repeat content (like paragraphs, table rows, or list items), use a loop
structure. Loops start with {{>>tag}}
and end with
{{<<}}
, where "tag" refers to the name of your array of data.
Here's an example:
{{ FruitName }}
{{<<}}
Provide an array in your data to populate the loop:
{
"HealthyFood": [
{ "FruitName": "Apple" },
{ "FruitName": "Banana" },
{ "FruitName": "Orange" }
]
}
The resulting document will contain the list of fruits:
Apple
Banana
Orange
Tip: Whitespaces before and after the tag name are ignored.
This means {{tag}}
is the same as {{ tag }}
and
{{>>tag}}
is the same as {{ >> tag }}
.
List and Table Loops
Loop tags can process text blocks, table rows, and list items. The service automatically detects the context and handles the repetition appropriately. So all of the following examples are valid:
Paragraphs
{{>> Pets }}{{ Name }} {{ Type }}
{{<<}}
List Items
- {{>> Pets }}{{ Name }} {{ Type }}{{<<}}
Table Rows
Name | Type |
{{>> Pets }}{{ Name }} | {{ Type }}{{<<}} |
Consider the following data:
{
"Pets": [
{ "Name": "Max", "Type": "Cat" },
{ "Name": "Leo", "Type": "Dog" }
]
}
The resulting document will contain the list of pets in the different formats requested:
Paragraphs
Max Cat
Leo Dog
List Items
- Max Cat
- Leo Dog
Table Rows
Name | Type |
Max | Cat |
Leo | Dog |
Conditions
To conditionally include content in your template, use a condition structure.
Conditions syntax is similar to loops, start with {{>>tag}}
and
end with {{<<}}
, where "tag" refers to a boolean value in your
data.
Here's an example:
Provide a boolean value in your data to control the condition:
{
"IsPremium": true,
"PremiumContent": "This is premium content!"
}
The content between the condition tags will only be included if the condition evaluates to true
.
Links
To insert hyperlinks in your template, use a link tag. Link tag syntax is the same as simple text replacement:
What makes it a link is the JSON data, that follows a specific structure:
{
"MyLink": {
"_type": "link",
"target": "https://example.com",
"text": "Click here", // optional
"tooltip": "Visit our website" // optional
}
}
The text
and tooltip
fields are optional. If text
is not provided, the target
URL will be used as the link text.
Images
To insert images in your template, use an image tag. Image tag syntax is the same as simple text replacement:
What makes it an image is the JSON data, that follows a specific structure:
{
"MyImage": {
"_type": "image",
"source": "base64 encoded image data",
"format": "image/jpeg",
"width": 800,
"height": 600,
"altText": "A beautiful sunset", // optional
"transparencyPercent": 0 // optional
}
}
The altText
and transparencyPercent
fields are optional. The transparencyPercent
value ranges from 0 to 100, where 0 means fully opaque and 100 means fully transparent.
Note: Image files must be less than 4MB in size and supported formats include JPEG, PNG, GIF, and BMP.