Skip to content

DocxTemplateFiller 1.0.0

Overview

Misc Beginner

Version Source

Description

Fills a DOCX template with provided data and saves the filled document to blob storage.

Configuration Options

NameData TypeDescriptionDefault Value
output_file_namestrName for the generated filled document file (without .docx extension)Completed_Template
template_fileFileDOCX template file containing Jinja2 template syntax for data insertion. Must be a valid .docx file with template variables.None

Inputs

NameData TypeDescription
dataDataStructured data object or JSON string containing key-value pairs to fill template variables. Keys must match template variable names in the DOCX file.

Outputs

NameData TypeDescription
created_FileFileFile object representing the completed DOCX document with all template variables filled. Uploaded to blob storage and ready for download or further processing.

Examples

# Basic contract template filling
- type: DocxTemplateFiller
  config:
    output_file_name: "Service_Contract_2024"
    template_file: "file_abc123"  # Contract template with customer info placeholders
  input:
    data:
      customer_name: "John Doe"
      service_type: "Web Development"
      start_date: "2024-01-15"
      contract_value: "15,000"
      project_duration: "6 months"

Error Handling

Template File Access Error

Error Code
ValueError
Common Cause
Invalid or empty template blob data retrieved from storage, or template file is corrupted/empty
Solution
Verify the template_file ID is correct and the file exists in blob storage. Ensure the DOCX template file is not corrupted and contains valid content.

Template Rendering Error

Error Code
Exception
Common Cause
Template variables in DOCX file don't match provided data keys, malformed Jinja2 syntax in template, or data structure incompatibility
Solution
Ensure all template variables in the DOCX file have corresponding keys in the data input. Check template syntax and verify data structure matches expected format. Review debug message for specific variable names causing issues.

Blob Storage Save Error

Error Code
Exception
Common Cause
Failed to save the filled document to blob storage due to storage service issues or insufficient permissions
Solution
Check blob storage service connectivity and permissions. Ensure sufficient storage quota is available. Verify the output file name doesn't contain invalid characters.

FAQ

What template syntax should I use in my DOCX file?

Use Jinja2 template syntax in your DOCX file. For simple variable substitution, use double curly braces like Dear Name. For loops, use for item in items and endfor. For conditionals, use if condition and endif. Ensure all opening template tags have corresponding closing tags to prevent rendering errors.

How do I handle nested data structures in templates?

Access nested properties using dot notation, such as company.name or client.address. For arrays, you can loop through them using for item in line_items and access properties like item.description within the loop. Make sure your data structure exactly matches the template variables.

What happens if my data doesn't match template variables?

If template variables don't have corresponding data keys, the block will throw a template rendering error with detailed debug information including the specific variable names causing issues. Review the error message to identify missing data fields and ensure your input data structure includes all required variables.

Can I pass data as a JSON string instead of an object?

Yes, the block automatically detects and parses JSON strings into objects. You can pass structured data either as a dictionary object or as a valid JSON string, and the block will handle the conversion internally before template processing.

What file formats are supported for templates?

Only DOCX format is supported for templates. The template must be a valid Microsoft Word document (.docx) containing Jinja2 template syntax. Other formats like DOC, PDF, or TXT are not compatible with this block.