Products Technologies Demo Docs Blog Support Company

ReportingCloud: Conditional Text Blocks Based on Merge Blocks

In several applications, it is required to render or to remove a complete text block in a template based on specific conditions. The following screenshot shows a template with a merge block (highlighted in red) that should be rendered, if the merge data contains data for this specific block with the name conditional: Consider, we have the following classes as the data source in C# .NET: The following code creates a new instance of the data class Report and an empty Conditional class. In the…

ReportingCloud: Conditional Text Blocks Based on Merge Blocks

In several applications, it is required to render or to remove a complete text block in a template based on specific conditions. The following screenshot shows a template with a merge block (highlighted in red) that should be rendered, if the merge data contains data for this specific block with the name conditional:

ReportingCloud: Conditional text blocks based on merge blocks

Consider, we have the following classes as the data source in C# .NET:

public class Report
{
    public string name { get; set; }
    public Conditional conditional { get; set; }
}

public class Conditional
{
    public string test { get; set; }
}

The following code creates a new instance of the data class Report and an empty Conditional class. In the MergeSettings object, which is part of the ReportingCloud MergeBody, the RemoveEmptyBlocks property is set to true.

Report report = new Report();
report.name = "Name";
report.conditional = new Conditional();

ReportingCloud rc = new ReportingCloud("username", "password");

MergeBody body = new MergeBody();
body.MergeData = report;
body.MergeSettings = new MergeSettings() {
    RemoveEmptyBlocks = true
};

List<byte[]> docs = rc.MergeDocument(body, "conditional_template.tx", ReturnFormat.TX);

In case, the data for the merge block conditional is empty, the complete merge block gets removed, if RemoveEmptyBlocks is set to true. The following animation shows the result for both cases:

ReportingCloud: Conditional text blocks based on merge blocks

The logic that defines which block gets rendered or removed is not part of the template, but your data source and therefore, part of your application.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Cloud

Are we moving to the cloud? This question is changing from "if" to "when" and "how". Text Control ReportingCloud brings complete reporting functionality to the cloud so all developers can use it, irrespective of the platform or language they're using. Its highly RESTful API can be used to merge Microsoft Word compatible templates with JSON data from all clients including .NET, Javascript, PHP, Node.JS, jQuery, Ruby, Python, Android, Java and iOS.

See Cloud products

Related Posts

CloudReportingMail Merge

ReportingCloud: Uploading Templates Vs. Sending Templates Inside MergeBody

Our reporting Web API ReportingCloud provides two different ways to upload templates for merging processes: Upload templates into the template storage in a separate step Upload templates inside…


CloudReportingMail Merge

MailMerge: Table Headers and Repeating Blocks

When using table headers and repeating blocks in combination in a MailMerge process, there are some things you need to know before creating your templates. A table header can consist of n number…


CloudReportingMail Merge

Web API Test Sandbox Released on ReportingCloud Portal

We just released a Web API Test Sandbox at the ReportingCloud portal. This sandbox can be used to test Web API calls with your account data and your template storage (so not a completely isolated…


CloudReportingMail Merge

ReportingCloud: New Test Parameter for Document Quota Related Endpoints

The quota related endpoints merge, convert and findandreplace received the new, optional parameter test to send test calls that doesn't count against the document quota. This parameter allows you…


CloudReportingMail Merge

ReportingCloud: The MergeData JSON Object Format Explained

When merging templates with data, a JSON object contains merge data for all merge fields and merge blocks in the document. Using the language specific wrappers, the JSON object is created…