改进模板包含文件对动态变量的支持

This commit is contained in:
oldrind
2016-02-04 11:39:12 +08:00
parent 4d7eb0b8a0
commit 7c24df26dd
2 changed files with 38 additions and 13 deletions

View File

@@ -252,11 +252,13 @@ EOF;
$config['tpl_path'] = dirname(__FILE__) . '/';
$config['tpl_suffix'] = '.html';
$template = new Template($config);
$files = ['extend' => 'extend', 'include' => 'include'];
$template->assign('files', $files);
$content = <<<EOF
{extend name="extend" /}
{extend name="\$files.extend" /}
{block name="side"}
{include file="include" name="\$user.name" value="\$user.account" /}
{include file="\$files.include" name="\$user.name" value="\$user.account" /}
{\$message}{literal}{\$message}{/literal}
{/block}
EOF;
@@ -374,4 +376,12 @@ EOF;
$value = $template->get('name');
$this->assertEquals('value', $value);
}
public function testVarGet()
{
$template = new Template();
$data = ['a' => 'a', 'b' => 'b'];
$template->assign($data);
$this->assertEquals($data, $template->get());
}
}