Skip to main content

Building and Configuring Data Export Templates

Data export templates enable you to transform extracted document data into standardized output formats (XML) using the Mustache templating language. Each template is tied to a specific document type and format, with only one active template per document type-format combination. Templates support dynamic variable insertion, conditional rendering, and iterative structures to handle complex data transformations without requiring code changes.

How It Works

Accessing the Data Export Templates Interface

  1. Navigate to Settings in the main menu

  2. Select Data Export Templates

  3. View the list of existing templates organized by document type and format

Creating a New Data Export Template

  1. Click + Add New button

  2. Enter a descriptive template name following the versioning convention: DocumentType-Format-Region-vX.X

    • Example: UBL-Invoice-Nordics-v1.0, PEPPOL-Invoice-EMEA-v2.1

  3. Select the Document Type from the dropdown (Invoice, Purchase Order, etc.)

  4. Click Create to proceed to the template editor

Building the Template in the Live Editor

  1. The Template Editor opens with three main sections:

    • Variable Panel (left): Displays available variables for the selected document type

    • Live Editor (center): Edit template code with real-time validation

    • Format Selector (right): Confirms selected output format

  2. Insert variables into your template:

    • Click the + icon next to a variable name to insert it at the cursor position

    • Or search the variable panel and click to insert

    • Variables appear in Mustache syntax: {variable_name}

  3. Common variables include:

    • {buyer_name}, {buyer_address}, {buyer_vat}

    • {seller_name}, {seller_address}, {seller_email}

    • {invoice_number}, {invoice_date}, {due_date}

    • {total_amount}, {subtotal}, {vat_rate}, {vat_amount}

    • {line_items} (array), {payment_terms}

Handling Missing Fields

  1. Use optional Mustache syntax to gracefully handle missing data:

    {{#buyer_name}}Buyer: {{buyer_name}}{{/buyer_name}}
    {{^buyer_name}}No buyer specified{{/buyer_name}}
  2. Wrap optional sections in conditional blocks to prevent rendering empty tags

  3. Provide fallback values using conditional logic:

    {{#total_amount}}{{total_amount}}{{/total_amount}}
    {{^total_amount}}0.00{{/total_amount}}

Validating Template Structure

  1. The live editor provides real-time validation:

    • XML templates: Validates well-formed XML structure

    • JSON templates: Validates syntactically correct JSON

    • CSV templates: Validates proper comma and quote escaping

  2. Red error indicators appear inline if validation fails; hover to view error details

  3. Test with sample data by clicking Validate to check against template structure

Saving and Activating Templates

  1. Click Save when template validation passes

  2. Only one template per document type-format combination can be active at a time

  3. If saving a template for an already-active document type-format pair, you are prompted to replace the active template

  4. Archive old versions by following naming convention (e.g., change version from v1.0 to v1.0-archived)

Using Transformations for Complex Logic

  1. Do NOT hardcode values directly into templates

  2. Use the Transformations feature (if available in your plan) to:

    • Convert date formats: ISO 8601 → DD/MM/YYYY

    • Calculate derived fields: subtotal + tax = total

    • Normalize country codes or currency symbols

    • Apply business rules (e.g., round amounts to 2 decimals)

  3. Transformations are applied before variable substitution, ensuring clean data in templates

Supported Configurations and Options

Configuration

Description

Options

Required

Template Name

Versioned identifier

DocumentType-Format-Region-vX.X format

Yes

Document Type

Applicable document classification

Invoice, PO, Credit Note, Despatch Advice, Receipt

Yes

Export Format

Output structure type

XML, JSON, CSV

Yes

Active Status

Only one active per doc-type-format

Single selection

No (auto-selected on first save)

Mustache Variables

Dynamic data insertion

Any supported variable from extraction

Yes (at least one)

Optional Sections

Conditional rendering

Mustache {{#variable}}...{{/variable}} syntax

No

Array Iteration

Repeat sections for lists

Mustache {{#line_items}}...{{/line_items}}

Conditional

Fallback Values

Default for missing data

Hardcoded strings in conditionals

No

Technical Specifications

Aspect

Details

Templating Language

Mustache (Logic-less templates)

Variable Format

Curly braces: {variable_name} or Mustache: {{variable_name}}

Variable Scope

Document-type specific; not all variables available for all doc types

Maximum Template Size

1 MB per template

Supported Formats

XML, JSON, CSV

One Active Per

Document Type + Export Format combination

Version Control

Maintained via naming convention (not system-enforced)

Validation Scope

Syntax only; semantic validation relies on transformation rules

Encoding

UTF-8 for all formats

Special Characters

Properly escaped by live editor during export

Integration Points

  • Document Extraction Pipeline: Variables are populated from extraction results before template rendering

  • Data Transformations: Applied before variable substitution to clean and normalize data

  • Export API: Templates referenced by document type and format when exporting via REST API

  • Scheduled Exports: Templates can be applied to bulk export jobs

  • Audit Logs: Template creation, modification, and activation are recorded

  • Multi-format Support: Same document can be exported to multiple formats using different active templates

Known Limitations and Edge Cases

  • One Active Template Per Document Type-Format: If you need multiple variations, use versioned naming and manually switch active templates

  • No Conditional Document Type Selection: Templates are tied to a single document type; cross-document-type logic is not supported

  • Array Handling: Nested arrays (e.g., line items within line items) require careful Mustache syntax; deeply nested structures may become difficult to manage

  • Large Datasets: Exporting documents with very large line item counts (1000+) may result in large file sizes; consider pagination for bulk exports

  • Hardcoded Values Not Recommended: Avoid hardcoding business logic or static data; use Transformations instead for maintainability

  • Variable Typos: Misspelled variable names render as empty strings; validation does not catch unused variables

  • Format Conversion Limitations: CSV export has limited support for nested structures; complex hierarchical data exports better as XML or JSON


Related Articles

  • Understanding Document Extraction and Variable Mapping

  • Data Transformations and Custom Logic

  • Using the REST API for Data Export

  • Bulk Export and Scheduled Jobs

  • Template Versioning and Management Strategy

Change Log

Date

Author

Notes

2026-04-24

Docupath Team

Initial version

Did this answer your question?