变量赋值
assign 标签也是用于页面快捷赋值,这个还是用起来比较方便。
node 版本.初始化为 Null 值
{
$parser = $this->createParser();
$source = <<<'eot'
<assign name="test.hello" />
eot;
$compiled = <<<'eot'
<?php $test->hello = null; ?>
eot;
$this->assertSame($compiled, $parser->doCompile($source, null, true));
}
node 版本.初始化为指定变量
public function testNode2()
{
$parser = $this->createParser();
$source = <<<'eot'
<assign name="test.hello" value="$hello" />
eot;
<?php $test->hello = $hello; ?>
eot;
$this->assertSame($compiled, $parser->doCompile($source, null, true));
}
node 版本.初始化为函数格式化占位变量
{
$parser = $this->createParser();
$source = <<<'eot'
<assign name="test.hello" value="$hello|test=0,1|foo=**" />
eot;
$compiled = <<<'eot'
<?php $test->hello = foo(test($hello, 0,1)); ?>
eot;
$this->assertSame($compiled, $parser->doCompile($source, null, true));
}
JS 风格版本
public function testLet()
{
$parser = $this->createParser();
$source = <<<'eot'
{% let foo = 'foo' %}
{% let hello = hello . 'foo' %}
eot;
$compiled = <<<'eot'
<?php $foo = 'foo'; ?>
<?php $hello = $hello . 'foo'; ?>
}
JS 风格版本.初始化为 Null 值
public function testLet3()
{
$parser = $this->createParser();
$source = <<<'eot'
{% let foo %}
eot;
$compiled = <<<'eot'
<?php $foo = null; ?>
eot;
$this->assertSame($compiled, $parser->doCompile($source, null, true));
}
JS 风格版本.初始化为 Null 值带上等于符
public function testLet4()
{
$parser = $this->createParser();
$source = <<<'eot'
{% let foo = %}
eot;
$compiled = <<<'eot'
<?php $foo = null; ?>
eot;
}