变量赋值

    assign 标签也是用于页面快捷赋值,这个还是用起来比较方便。

    node 版本.初始化为 Null 值

    1. {
    2. $parser = $this->createParser();
    3. $source = <<<'eot'
    4. <assign name="test.hello" />
    5. eot;
    6. $compiled = <<<'eot'
    7. <?php $test->hello = null; ?>
    8. eot;
    9. $this->assertSame($compiled, $parser->doCompile($source, null, true));
    10. }

    node 版本.初始化为指定变量

    1. public function testNode2()
    2. {
    3. $parser = $this->createParser();
    4. $source = <<<'eot'
    5. <assign name="test.hello" value="$hello" />
    6. eot;
    7. <?php $test->hello = $hello; ?>
    8. eot;
    9. $this->assertSame($compiled, $parser->doCompile($source, null, true));
    10. }

    node 版本.初始化为函数格式化占位变量

    1. {
    2. $parser = $this->createParser();
    3. $source = <<<'eot'
    4. <assign name="test.hello" value="$hello|test=0,1|foo=**" />
    5. eot;
    6. $compiled = <<<'eot'
    7. <?php $test->hello = foo(test($hello, 0,1)); ?>
    8. eot;
    9. $this->assertSame($compiled, $parser->doCompile($source, null, true));
    10. }

    JS 风格版本

    1. public function testLet()
    2. {
    3. $parser = $this->createParser();
    4. $source = <<<'eot'
    5. {% let foo = 'foo' %}
    6. {% let hello = hello . 'foo' %}
    7. eot;
    8. $compiled = <<<'eot'
    9. <?php $foo = 'foo'; ?>
    10. <?php $hello = $hello . 'foo'; ?>
    11. }

    JS 风格版本.初始化为 Null 值

    1. public function testLet3()
    2. {
    3. $parser = $this->createParser();
    4. $source = <<<'eot'
    5. {% let foo %}
    6. eot;
    7. $compiled = <<<'eot'
    8. <?php $foo = null; ?>
    9. eot;
    10. $this->assertSame($compiled, $parser->doCompile($source, null, true));
    11. }

    JS 风格版本.初始化为 Null 值带上等于符

    1. public function testLet4()
    2. {
    3. $parser = $this->createParser();
    4. $source = <<<'eot'
    5. {% let foo = %}
    6. eot;
    7. $compiled = <<<'eot'
    8. <?php $foo = null; ?>
    9. eot;
    10. }