Sponsored Link

foreach + ifdef

ifdef タグは、foreach タグ内でも利用可能です。

PHP

$assign['sample_foreach11']['a1'] = 'foo';
$assign['sample_foreach11']['a2'] = 'dummy';
$assign['sample_foreach11']['a3'] = 'bar';
unset($assign['sample_foreach11']['a2']);        // check for ifdef

Template

{{ @foreach sample_foreach11 }}
    {{ @ifdef @key }}
        defined : {{ @val }}
    {{ @elsedef }}
        undefined
    {{ @endifdef }}
    <br>
{{ @endforeach }}

Result

defined : foo
defined : bar