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:

{{ FirstName }}

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.

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 ✗
{{FirstName}}{FirstName}
{{ firstName }}{ { firstName } }
{{ FirstName }}{{ First Name }}
{{ last_name }}{{ last-name }}
{{first_name}}{{_first_name}}
{{ 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:

{{>> HealthyFood }}
{{ 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 ✗
{{>> Items }}{{# Items }}
{{<<}}{{/ Items }}
{{>> Items }}
{{ ItemName }}
{{<<}}
{<< Items }
{ ItemName }
{<<}