In version X13, a new property has been introduced that specifies whether the content of empty merge blocks should be removed from the template or not: RemoveEmptyBlocks. This can be very helpful for dynamic templates where under specific circumstances, a complete block should be rendered or not.

Consider the following sample class structure that is used as the merge data object:

public class Data
{
public string Field { get; set; }
public Appendix Appendix { get; set; }
}
public class Appendix
{
public string Field1 { get; set; }
}
view raw tx.cs hosted with ❤ by GitHub

The name of the dynamic block in the template is Appendix and the master object is Data. If the property Appendix of the class Data has been set to a valid object of type Appendix, the block data exists and is merged.

Appendix appendix = new Appendix()
{
Field1 = "Field 1 Text"
};
Data data = new Data() {
Field = "Field Text",
Appendix = appendix
};
using (MailMerge mailMerge1 = new MailMerge())
{
mailMerge1.TextComponent = textControl1;
mailMerge1.RemoveEmptyBlocks =
removeEmptyBlocksToolStripMenuItem.Checked;
mailMerge1.MergeObject(data);
}
view raw tx.cs hosted with ❤ by GitHub

If the property RemoveEmptyBlocks of MailMerge is set to true (code line 14) and the merge data is missing (code line 8), the complete block gets removed.

This new concept allows you to create dynamic structures and conditional blocks in a template. Merge blocks are not necessarily blocks that repeat content. Using merge blocks, you can also define a named range of formatted text with data from another object.