Sponsored Link

if / elseif / else

'if/elseif/else' tag takes the actions that match the conditions by comparing the values and variables.
'else if' rather than, you must be described as 'elseif'.
Two conditions can be specified using '&&' or '||'.
'and/or' can not be used instead of '&&/||'.

Syntax

{{ @if operand operator operand }}
    statements
{{ @elseif operand operator operand }}
    statements
{{ @else }}
    statements
{{ @endif }}


{{ @if operand operator operand && operand operator operand }}
    statements
{{ @elseif operand operator operand && operand operator operand }}
    statements
{{ @else }}
    statements
{{ @endif }}


operand = val_name | string | numeral value
operator = Comparison Operators of PHP

PHP

$assign['sample_if1'] = false;
$assign['sample_if2']['a2'] = 'a, b, c';
$assign['sample_if3'] = 45;
$assign['sample_if4'] = true;
$assign['sample_if5']['a1'] = 'foo';
$assign['sample_if5']['a2'] = 'foo';

Template

{{ @if sample_if1 === 0 }}
    0
{{ @elseif sample_if1 === false }}
    false
{{ @elseif sample_if1 >= 100 }}
    over 100
{{ @else }}
    unknown
{{ @endif }}
<br>
{{ @if sample_if2.a2 === 'a, b, c' }}
    {{ sample_if2.a2 }}
{{ @else }}
    unknown
{{ @endif }}
<br>
{{ @if sample_if3 === sample_if4 }}
    same
{{ @else }}
    different
{{ @endif }}
<br>
{{ @if sample_if5.a1 === sample_if5.a2 }}
    same
{{ @else }}
    different
{{ @endif }}
<br>
{{ @if sample_if3 > 10 && sample_if4 === false }}
    conditions-if
{{ @elseif sample_if3 > 10 && sample_if4 === true }}
    conditions-elseif
{{ @else }}
    conditions-else
{{ @endif }}

Result

false
a, b, c
different
same
conditions-elseif