Skip to main content

DOCX Template Variables

DocuTrust supports variable substitution in DOCX templates. Use [[variable_name]] syntax to insert dynamic content, and [[if:variable]]...[[end]] for conditional blocks that appear only when a variable has a value.

Variable syntax

Basic variables

Wrap variable names in double square brackets:
When the document is processed, each [[variable_name]] placeholder is replaced with the corresponding field value from the signer’s submission. Example DOCX content:

Variable naming rules

Conditional blocks

Use [[if:variable]]...[[end]] to create sections that only appear when the referenced variable has a non-empty value.
If addendum_text is empty or not provided, the entire block (from [[if:addendum_text]] to [[end]]) is removed from the final document.

Nested conditionals

Conditional blocks can be nested:

Built-in variables

DocuTrust provides several built-in variables that are automatically available in every DOCX template. You do not need to define fields for these — they are populated from the submission context. Example using built-in variables:

Mapping fields to variables

DOCX variables are mapped to template fields by the field’s key property. When you create a template from a DOCX file, DocuTrust auto-detects [[variable_name]] placeholders and creates corresponding fields in the schema.

Automatic field creation

When uploading a DOCX with variables:
DocuTrust scans the document for [[variable]] placeholders and creates text fields for each one. The resulting template schema:
Built-in variables (signer_name, signer_email, signing_date, submission_id, template_name) are not created as fields since they are populated automatically from the submission context.

Pre-filling variables via submission

When creating a submission, pre-fill DOCX variables using the values object keyed by the field’s key property:

Formatting in DOCX

DOCX variables preserve the formatting of the surrounding text. If [[company_name]] is bold in the DOCX file, the substituted value will also be bold. Formatting rules:
Avoid splitting a variable placeholder across multiple runs in the DOCX XML. Word sometimes inserts formatting markers mid-word (e.g., [[company_ in one run and name]] in another). If variable substitution is not working, try retyping the entire [[variable_name]] placeholder in a single action.
To debug variable detection issues, download the template’s documents via the API and check the schema response. All detected variables appear as fields with matching key values.