Conditional Statements
Conditional statements allow you to dynamically control the display or hiding of content in the document based on data values. There are three main ways to write conditions:
- Inline conditions: Directly output text (or replace it with other text).
- Conditional blocks: Display or hide a section of the document, suitable for multiple tags, paragraphs, tables, etc.
- Smart conditions: Directly remove or keep target elements (like rows, paragraphs, images, etc.) with a single tag, for a more concise syntax.
All conditions begin with a logical evaluation formatter (e.g., ifEQ, ifGT, etc.), followed by action formatters (such as show, elseShow, drop, keep, etc.).
Overview
The logical operators and action formatters supported in conditional statements include:
-
Logical Operators
- ifEQ(value): Checks if the data is equal to the specified value.
- ifNE(value): Checks if the data is not equal to the specified value.
- ifGT(value): Checks if the data is greater than the specified value.
- ifGTE(value): Checks if the data is greater than or equal to the specified value.
- ifLT(value): Checks if the data is less than the specified value.
- ifLTE(value): Checks if the data is less than or equal to the specified value.
- ifIN(value): Checks if the data is contained in an array or string.
- ifNIN(value): Checks if the data is not contained in an array or string.
- ifEM(): Checks if the data is empty (e.g., null, undefined, an empty string, an empty array, or an empty object).
- ifNEM(): Checks if the data is non-empty.
- ifTE(type): Checks if the data type is equal to the specified type (for example, "string", "number", "boolean", etc.).
- and(value): Logical "and", used to connect multiple conditions.
- or(value): Logical "or", used to connect multiple conditions.
-
Action Formatters
- :show(text) / :elseShow(text): Used in inline conditions to directly output the specified text.
- :hideBegin / :hideEnd and :showBegin / :showEnd: Used in conditional blocks to hide or show sections of the document.
- :drop(element) / :keep(element): Used in smart conditions to remove or keep specified document elements.
The following sections introduce the detailed syntax, examples, and results for each usage.
Inline Conditions
1. :show(text) / :elseShow(text)
Syntax
Example
Assume the data is:
The template is as follows:
Result
2. Switch Case (Multiple Conditionals)
Syntax
Use consecutive condition formatters to build a structure similar to a switch-case:
Or achieve the same with the or operator:
Example
Data:
Template:
Result
3. Multi-variable Conditionals
Syntax
Use the logical operators and/or to test multiple variables:
Example
Data:
Template:
Result
Logical Operators and Formatters
In the following sections, the described formatters use the inline condition syntax with the following format:
1. :and(value)
Syntax
Example
Result
If d.car equals 'delorean' and d.speed is greater than 80, the output is TravelInTime; otherwise, the output is StayHere.
2. :or(value)
Syntax
Example
Result
If d.car equals 'delorean' or d.speed is greater than 80, the output is TravelInTime; otherwise, the output is StayHere.
3. :ifEM()
Syntax
Example
Result
For null or an empty array, the output is Result true; otherwise, it is Result false.
4. :ifNEM()
Syntax
Example
Result
For non-empty data (such as the number 0 or the string 'homer'), the output is Result true; for empty data, the output is Result false.
5. :ifEQ(value)
Syntax
Example
Result
If the data equals the specified value, the output is Result true; otherwise, it is Result false.
6. :ifNE(value)
Syntax
Example
Result
The first example outputs Result false, while the second example outputs Result true.
7. :ifGT(value)
Syntax
Example
Result
The first example outputs Result true, and the second outputs Result false.
8. :ifGTE(value)
Syntax
Example
Result
The first example outputs Result true, while the second outputs Result false.
9. :ifLT(value)
Syntax
Example
Result
The first example outputs Result true, and the second outputs Result false.
10. :ifLTE(value)
Syntax
Example
Result
The first example outputs Result true, and the second outputs Result false.
11. :ifIN(value)
Syntax
Example
Result
Both examples output Result true (because the string contains 'is', and the array contains 2).
12. :ifNIN(value)
Syntax
Example
Result
The first example outputs Result false (because the string contains 'is'), and the second example outputs Result false (because the array contains 2).
13. :ifTE(type)
Syntax
Example
Result
The first example outputs Result true (since 'homer' is a string), and the second outputs Result true (since 10.5 is a number).
Conditional Blocks
Conditional blocks are used to display or hide a section of the document, typically to enclose multiple tags or an entire block of text.
1. :showBegin / :showEnd
Syntax
Example
Data:
Template:
Result
When the condition is met, the content in between is displayed:
2. :hideBegin / :hideEnd
Syntax
Example
Data:
Template:
Result
When the condition is met, the content in between is hidden, resulting in:

