D
D
Developers
Search…
If / Else If / Else
The if flow evaluates the given expression and executes the body if the expression resulted in true. Otherwise, the body is ignored. It can be chained with else if and else, stopping the execution after the first expression resulting in true.
If must always start the condition chain and can be optionally followed by else if and else. Else has to always be the last, and can only be used in the chain.

Syntax

Basic syntax of if tag is as follows:
1
{[ if [statement] ]}
2
Content that gets executed when statement evaluates to true
3
{[/]}
Copied!
When additional conditions are needed, use else if and / or else to chain them:
1
{[ if [statement] ]}
2
Content that gets executed when first statement evaluates to true
3
{[ elseif [statement] ]}
4
Content that gets executed when first statement evaluates to false and second to true
5
{[ else ]}
6
Content that gets executed when everything above evaluates to false (fallback)
7
{[/]}
Copied!
Note that else doesn't have statement as it serves as a fallback when everything else fails.

Evaluating the statement

This section is a work in progress. If definition is not yet complete
if or else if evaluates to true when one of the following conditions is true:
  • statement resulting type is Boolean and == true
  • statement resulting type is Int and >= 1
  • statement resulting type is String and the string is not empty

Example use case

If can be used to render structurally different data based on the input values. In this example, a different user menu gets rendered based on whether the user is admin, team member, or a visitor.
Data
1
{
2
"user": {
3
"name": "Jiri",
4
"type": "member"
5
}
6
}
Copied!
Blueprint
1
<ul>
2
{[ if user.type.equals("admin") ]}
3
<li>Manage Database</li>
4
<li>Manage Users</li>
5
<li>Manage Team</li>
6
{[ elseif self.user.type.equals("member") ]}
7
<li>Manage Team</li>
8
{[ else ]}
9
<li>Request Membership</li>
10
{[/]}
11
<li>Logout</li>
12
</ul>
Copied!
Result
1
<ul>
2
<li>Manage Team</li>
3
<li>Logout</li>
4
</ul>
Copied!
Finally, if we change user.type to admin, the output will look like the following:
1
<ul>
2
<li>Manage Database</li>
3
<li>Manage Users</li>
4
<li>Manage Team</li>
5
<li>Logout</li>
6
</ul>
Copied!
Last modified 7mo ago