Typically, a merge block is used to repeat content such as table rows. But a merge block can be also used to control the rendering of a complete block such as a sub report.
Remove merge blocks by removing data
Consider the following data model:
The following screenshot shows the simple template for this sample. Highlighted in red, the merge block is shown:
The following code creates two instances of the data model. The first Report has a Products list and the second doesn't. If the MailMerge property is set to true (default), the missing data controls the rendering of the complete block.
In the results, you can see that the Products section gets rendered in the first report, but is completely removed in the second report:
If the data is missing, the merge block gets removed.
Render merge blocks based on conditions
Another way to control the merge block rendering is to compare a value of the merge block's parent table. Therefore, we change the data model a little bit:
A boolean value has been added to the parent object that should control whether the merge block is rendered or not.
The following codes creates the new data object. The Products data part is now available in both objects, but RenderProducts is used to specify whether the block is rendered or not:
This code is used to insert the merge block with the condition (if "RenderProducts" = true):
The results are the same. The merge block is rendered in the first case and it is not rendered in the second case: