The if…else statement executes some code if a condition is true and another code if that condition is false.
Syntax
:
XHTML
1
[if.else]Statementshere![/if.else]
Input Parameters
:
cond: (any) (Required) Left hand side value equal: (any) (Required) Right hand side value not_equal: (any) (Required) Right hand side valuenot_empty: Execute the block if not empty
Return Value
:
Code to be executed if condition is false
Example 1
:
Code
:
XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[if.equallhs="{template.age}"rhs="18"]
Statementshere!
[/if.equal]
[if.else]
Statementshere!
[/if.else]
---------------------------------------------
[if.equallhs="{template.age}"rhs="18"]
Statementshere!
[/if.equal]
[if.elsecond="{template.age}"equal="10"]
Statementshere!
[/if.else]
---------------------------------------------
[if.equallhs="{template.age}"rhs="18"]
Statementshere!
[/if.equal]
[if.elsenot_empty="{template.age}"]
Elsestatementshere!
[/if.else]
Output
:
It will display the text Else statements here!
Description
:
Very often when you write code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this.
if statement – executes some code if one condition is true if…else statement – executes some code if a condition is true and another code if that condition is false.