Sponsored Link

if / elseif / else

if/elseif/else タグは、値や変数を比較して条件に一致した処理を実行します。
'else if' ではなく、'elseif'(else と if の間に半角スペースを入れない)と記載する必要があります。
'&&' や '||' を利用した2つの条件を指定可能です。and/or の演算子は利用できません。

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