Condition Syntax
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:
{{ PremiumContent }}
{{<< }}
Provide a boolean value in your data to control the condition:
{
"IsPremium": true,
"PremiumContent": "This is a premium content!"
}
The content between the condition tags will only be included if the condition evaluates to true
.
Simple Example
Given this template:
Welcome{{>> IsRegistered }}, {{ Username }}{{<<}}!
The following data will be used to conditionally include the content:
{
"IsRegistered": true,
"Username": "John"
}
And the output document will be:
Welcome, John!
Alternatively, if the condition evaluates to false
:
{
"IsRegistered": false
}
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 ID | Status |
---|---|
{{>> Orders}}{{ID}} | {{Status}} {{>> IsPending}}(Estimated: {{DeliveryDate}}){{<<}}{{<<}} |
Remember to close both the condition tag and the loop tag with {{<<}}
for each.
The data for this template:
{
"Orders": [
{
"ID": "ORD-01",
"Status": "Completed",
"IsPending": false
},
{
"ID": "ORD-02",
"Status": "Pending",
"IsPending": true,
"DeliveryDate": "2024-03-15"
},
{
"ID": "ORD-03",
"Status": "Completed",
"IsPending": false
}
]
}
The output document will look like this:
Order ID | Status |
---|---|
ORD-01 | Completed |
ORD-02 | Pending (Estimated: 2024-03-15) |
ORD-03 | Completed |