fetch() публичный Метод

渲染模板文件
public fetch ( string $template, array $vars = [], array $config = [] ) : void
$template string 模板文件
$vars array 模板变量
$config array 模板参数
Результат void
Пример #1
0
    public function testFetch()
    {
        $template = new Template();
        $template->tpl_path = dirname(__FILE__) . '/';
        $data = ['name' => 'value'];
        $content = <<<EOF
{\$name}
EOF;
        $template->fetch($content, $data);
        $this->expectOutputString('value');
    }
Пример #2
0
    public function testFetch()
    {
        $config['view_path'] = dirname(__FILE__) . '/';
        $config['view_suffix'] = '.html';
        $config['layout_on'] = true;
        $config['layout_name'] = 'layout';
        $template = new Template($config);
        $files = ['extend' => 'extend', 'include' => 'include'];
        $template->assign('files', $files);
        $template->assign('user', ['name' => 'name', 'account' => 100]);
        $template->assign('message', 'message');
        $template->assign('info', ['value' => 'value']);
        $content = <<<EOF
{extend name="\$files.extend" /}
{block name="main"}
main
{block name="side"}
{__BLOCK__}
    {include file="\$files.include" name="\$user.name" value="\$user.account" /}
    {\$message}{literal}{\$message}{/literal}
{/block}
{block name="mainbody"}
    mainbody
{/block}
{/block}
EOF;
        $content2 = <<<EOF
<nav>
header
<div id="wrap">
    <input name="info" value="value">
value:

main


    side

    <input name="name" value="100">
value:
    message{\$message}


    mainbody



    {\$name}

    php code</div>
</nav>
EOF;
        $template->fetch($content);
        $this->expectOutputString($content2);
        //        $template->parse($content);
        //        var_dump($content);
    }