Skip to content

DOCX

Template type (numeric) Supports automatic variable detection
1

To utilize .docx template files, upload them during the creation process after creating/editing them in the office suite.

Text variables

Template variables utilize the following syntax:

{{ variableName }}

You may utilize whitespaces to surround the variable name while preserving template correctness:

{{       thisWorksToo  }}

Variable detection

.docx files can be unpredictable in terms of variable detection.

After creating a template, verify that all variables were auto-detected, as only these variables are utilized during the printing process.

Image variables

Document Rails relies on "Alternative text" functionality to detect image template variables.

To accommodate existing accessibility functionality of your documents, Document Rails automatically removes the variable placeholder before rendering the final document.

Example "Alternative text" value:

{{ __impressum_qrcode }} This is a QR code.

During the rendering process, Document Rails will transform this example into This is a QR code. to preserve document accessibility.

Name collision prevention

Usually, Document Rails provides automatically generated variables under the __impressum_ prefix.

To prevent any potential collisions, it is best to avoid using the same prefix for your custom variables.

Automatically generated variables are prioritized over the provided ones.

Examples

import { createTemplate, TemplateType } from "@vaultie/document-rails";

const response = await createTemplate(
    client,
    accessToken,
    organizationId,
    {
        // Select the .docx template type.
        template_type: TemplateType.Docx,

        // .docx file itself.
        file: new Blob([await readFile("./template.docx")]),

        // With .docx, we can rely on automatic variable detection
        // to specify `template_vars` field for us.
        //
        // In general, if the variable is not automatically detected by
        // Document Rails, it means that the document layout is malformed.
    }
);