Conditions

To conditionally include content in your template, use a condition structure. Conditions syntax is similar to loops, start with {{>>tag}} and end with {{<<}}, where "tag" refers to a boolean value in your data:

{{>> IsPremium }}
{{ PremiumContent }}
{{<< }}

Provide a boolean value in your data to control the condition:

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

The content between the condition tags will only be included if the condition evaluates to true (the checkbox is checked).

Simple Example

Given this template:

Welcome{{>> IsRegistered }}, {{ Username }}{{<<}}!

The following data will be used to conditionally include the content:

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

And the output document will be:

Welcome, John!

Alternatively, if the condition evaluates to false (the checkbox is unchecked):

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

The output document will be:

Welcome!

Advanced Example

This example demonstrates conditions within a table loop. The template shows a sales report where we display additional status information for pending orders:

Order IDStatus
{{>> Orders}}{{ID}}{{Status}} {{>> IsPending}}(Estimated: {{DeliveryDate}}){{<<}}{{<<}}

The data for this template:

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

The output document will look like this:

Order IDStatus
ORD-01Completed
ORD-02Pending (Estimated: 2024-03-15)
ORD-03Completed
Conditions - TemplateDocs Documentation