For 循环
node 简单版
{
$parser = $this->createParser();
$source = <<<'eot'
<for start='1'>
QueryPHP - node - for <br>
</for>
eot;
$compiled = <<<'eot'
<?php for ($var = 1; $var <= 0; $var += 1): ?>
QueryPHP - node - for <br>
eot;
$this->assertSame($compiled, $parser->doCompile($source, null, true));
}
JS 风格版: 例 1
{
$parser = $this->createParser();
$source = <<<'eot'
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% /for %}
eot;
$compiled = <<<'eot'
<?php foreach ($navigation as $key => $item): ?>
<li><a href="<?php echo $item->href; ?>"><?php echo $item->caption; ?></a></li>
<?php endforeach; ?>
eot;
$this->assertSame($compiled, $parser->doCompile($source, null, true));
}
JS 风格版: 例 3
{
$parser = $this->createParser();
$source = <<<'eot'
{% for mykey item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% /for %}
eot;
$compiled = <<<'eot'
<?php foreach ($navigation as $mykey => $item): ?>
<li><a href="<?php echo $item->href; ?>"><?php echo $item->caption; ?></a></li>
<?php endforeach; ?>
eot;
$this->assertSame($compiled, $parser->doCompile($source, null, true));