> ## Documentation Index
> Fetch the complete documentation index at: https://signatureapi-daf4ee54.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Document Templates

> Generate documents from DOCX templates and dynamic data.

SignatureAPI can generate a document from a static DOCX template combined with dynamic data you provide. Use this to create personalized documents without editing files manually before each send.

<Note>To add signature fields or display dynamic values like a recipient's name, see [Places](/docs/api/resources/places/object).</Note>

## How it works

Create a DOCX file and embed **fields** and **conditionals** using double curly braces: `{{key}}`. When you create an envelope, provide the data in the `data` property of the document. SignatureAPI merges the template with your data and produces the final document.

Provide the template URL in the `url` property and set `format` to `docx`.

```json theme={null}
// POST https://api.signatureapi.com/v1/envelopes
// X-API-Key: key_test_...
// Content-Type: application/json

{
  "title": "Exploration Agreement",
  "documents": [
    {
      "url": "https://www.example.com/agreement-template.docx",
      "format": "docx",
      "data": {
        "person": {
          "name": "Sherlock Holmes",
          "address": "221b Baker Street, London"
        },
        "jurisdiction": "The United Kingdom",
        "mediation": false
      }
    }
  ],
  //...
}
```

<Tip>DOCX files created with software other than Microsoft Word (like Google Docs or LibreOffice) may not process correctly. If you get a [cannot-parse-document](/docs/v1/errors/cannot-parse-document) error, open the file in Microsoft Word and save it again. Contact support if you don't have Microsoft Word.</Tip>

<Note>
  **`{{double curly braces}}` vs `[[double brackets]]`**: these serve different purposes:

  * `{{field_key}}`: **Template fields.** Inject dynamic content (names, dates, addresses) into the document text before signing. Only available in DOCX documents.
  * `[[place_key]]`: **Place placeholders.** Position signature fields, text inputs, checkboxes, and other interactive places. Works in both PDF and DOCX documents. See [Place Positioning](/docs/api/resources/places/positioning).

  A DOCX document can use both: `{{}}` to inject content and `[[]]` to position places.
</Note>

## Fields

Fields mark locations in the template where data is inserted. Use double curly braces to define a field: `{{key}}`.

**Template:**

<div className="border p-2">
  This agreement is entered into by \{\{name}}.
</div>

**Data:**

```json theme={null}
{
  "name": "Sherlock Holmes"
}
```

**Result:**

<div className="border p-2">
  This agreement is entered into by Sherlock Holmes.
</div>

### Nested objects

Data values can be nested objects. Use dot notation in the template to reference nested keys.

**Template:**

<div className="border p-2">
  This agreement is entered into by \{\{person.name}}, residing at \{\{person.address.houseNumber}} \{\{person.address.streetName}}, \{\{person.address.city}}.
</div>

**Data:**

```json theme={null}
{
  "person": {
    "name": "Sherlock Holmes",
    "address": {
      "houseNumber": "221b",
      "streetName": "Baker Street",
      "city": "London"
    }
  }
}
```

**Result:**

<div className="border p-2">
  This agreement is entered into by Sherlock Holmes, residing at 221b Baker Street, London.
</div>

## Conditionals

Conditionals control which sections appear in the final document based on your data.

### If

Use `{{if condition}}` and `{{endif}}` to show or hide a block of content.

**Template:**

<div className="border p-2">
  Please read before proceeding.

  \{\{if showDisclaimer}}<br />
  Information provided is for educational purposes only and should not be considered as professional advice.<br />
  \{\{endif}}

  Use at your own discretion.
</div>

With `"showDisclaimer": true`, the disclaimer appears. With `"showDisclaimer": false`, it is omitted.

### If-Else

Use `{{if condition}}`, `{{else}}`, and `{{endif}}` to display one of two blocks based on a condition.

**Template:**

<div className="border p-2">
  \{\{if mediation}}<br />
  Any dispute shall be resolved by mediation, with each party bearing its own costs.<br />
  \{\{else}}<br />
  Any dispute shall be settled by arbitration, and the arbitrator's decision is final.<br />
  \{\{endif}}<br />
</div>

With `"mediation": true`:

<div className="border p-2">
  Any dispute shall be resolved by mediation, with each party bearing its own costs.
</div>

With `"mediation": false`:

<div className="border p-2">
  Any dispute shall be settled by arbitration, and the arbitrator's decision is final.
</div>
