Merge Data into Template Word Document without using Merge Fields using Mustache Template Syntax C# .NET

Hello Aspose,

Are there any examples of using this ?

Cheers, Paul

Hi Paul,

Thanks for your interest in this feature.

I will describe the basic features of this new mail merge syntax. There will be a proper article in the documentation dedicated to this new feature later on.

Using the new template syntax you can merge data into places in the document at plain text markers that look like this: {{FieldName}}

You can enable this feature by using MailMerge.UseNonMergeFields . This functionality can allow you to merge data into template without the need for merge fields.

There is some additional syntax you can use with these new fields:

Object.Attribute Syntax

You can easily merge attributes of fields using the following syntax

{{Address.Street}}

This will merge data from XML data which looks like this:

// ← Current context is here.<o:p></o:p>

23

Nelson Street

Howick

Auckland

543 1234

Foreach Blocks

You can merge data from multiple records using the foreach tag. This is similar to mail merge regions with convectional merge fields. You can nest such blocks.

{{#foreach Order}}

{{Number}}

{{Address.Street}}

{{#foreach Item}}

{{Description}} {{Cost}} {{Total}}

{{/foreach Item}}

{{/foreach Order}}

You can also mix these fields and place them inside other Microsoft Word fields such as IF or Formula fields.

As an example I have attached a sample template and data source which is the equivalent of the Nested MailMerge sample but using this new syntax.

If I can help with anything else, please feel free to ask.

Thanks,