Skip to main content

Word Template Syntax - Merge Field Guide

Document generation using mail merge is the process of reading data from a data source and replacing corresponding variables in a template document. This approach streamlines the creation of personalized documents at scale, combining fixed content with dynamic data.

Understanding Mail Merge Templates

A typical mail merge process requires two essential components:

  1. Template Document - Contains merge fields (variables) that will be replaced with actual data
  2. Data Source - Contains both formatting instructions and the information that remains identical across each generated document

PDF4me supports multiple template formats including Word, HTML, and PDF documents, providing flexibility in how you create and structure your document templates.


Basic Merge Field Syntax

To create merge fields in your Word templates, use the following syntax:

<<[FieldName]>>

This syntax defines placeholders in your template that will be replaced with actual data during the document generation process.

Manual Merge Field Creation

You can manually insert merge fields directly into your Word document by typing the syntax shown above. The field name should match the corresponding property in your data source.

manual-merge-field

Example Usage

Template:

Dear <<[CustomerName]>>,

Thank you for your order #<<[OrderNumber]>>.

Data Source (JSON):

{
"CustomerName": "John Smith",
"OrderNumber": "12345"
}

Generated Output:

Dear John Smith,

Thank you for your order #12345.

Template Design Best Practices

Field Naming Conventions

  • Use descriptive, meaningful field names
  • Follow consistent naming patterns (e.g., camelCase or PascalCase)
  • Avoid special characters in field names
  • Keep field names concise yet clear

Template Organization

  • Structure your template logically before adding merge fields
  • Apply formatting to merge fields in the template itself
  • Test templates with sample data before production use
  • Maintain template versions for different document types

Supported Template Formats

PDF4me accepts the following template formats for document generation:

  • Word Documents (.docx, .doc) - Full support for Word template syntax
  • HTML Templates (.html) - Web-based template structures
  • PDF Templates (.pdf) - Form-based PDF templates

Each format supports the same merge field syntax, ensuring consistency across different template types.


Next Steps

Now that you understand the basic syntax, explore advanced template features:


Creating Advanced Templates

For detailed guidance on creating sophisticated Word templates with advanced features, refer to our comprehensive template documentation in the following sections.