Sponsored Link

foreach + if

if tag is also available in the foreach tag.

PHP

$assign['sample_foreach6'][] = array('id'=>1);
$assign['sample_foreach6'][] = array('id'=>TRUE);
$assign['sample_foreach6'][] = array('id'=>0);
$assign['sample_foreach6'][] = array('id'=>FALSE);
$assign['sample_foreach6'][] = array('id'=>'String');
$assign['sample_foreach6'][] = array('id'=>null);

Template

{{ @foreach sample_foreach6 }}
    {{ @if .id === null }}
        if : null<br>
    {{ @elseif .id === 0 }}
        elseif : 0<br>
    {{ @elseif .id === TRUE }}
        elseif : TRUE<br>
    {{ @else }}
        else : {{ .id }}<br>
    {{ @endif }}
{{ @endforeach }}

Result

else : 1
elseif : TRUE
elseif : 0
else :
else : String
if : null