Template Syntax Basics
TemplateDocs uses a simple and powerful template syntax that allows you to create dynamic documents from your Word templates. 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.
If you haven't already, make sure to read the Introduction guide.
Tag Rules
Tags are:
- surrounded by double curly braces
{{
and}}
- case-sensitive
- must start with a letter
- can contain letters, numbers, and underscores
- must not contain spaces in the tag name
- can contain spaces before and after the tag name
Examples:
Good ✓ | Bad ✗ | |
---|---|---|
Double curly braces, not single curly braces | {{FirstName}} | {FirstName} |
Double curly braces without spaces | {{ firstName }} | { { firstName } } |
No spaces in tag name | {{ FirstName }} | {{ First Name }} |
No special characters except underscores | {{ last_name }} | {{ last-name }} |
No underscores at the beginning | {{first_name}} | {{_first_name}} |
No numbers at the beginning | {{ Item5 }} | {{ 5Item }} |
Loop Tags
To repeat content (like paragraphs, table rows, or list items), use a loop structure. Loop tags consist of:
- An opening tag:
{{>> tag }}
- Content to be repeated
- A closing tag:
{{<<}}
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
Some examples to help you with the syntax:
Good ✓ | Bad ✗ | |
---|---|---|
Opening tag | {{>> Items }} | {{# Items }} |
Closing tag | {{<<}} | {{/ Items }} |
Surrounded by double curly braces | {{>> Items }} {{ ItemName }} {{<<}} | {<< Items } { ItemName } {<<} |
Spaces around tag names (but not within them) are allowed and will be ignored.
This means {{FirstName}}
is the same as {{ FirstName }}
and
{{>>HealthyFood}}
is the same as {{ >> HealthyFood }}
.