think\Template::display PHP Method

display() public method

渲染模板内容
public display ( string $content, array $vars = [], array $config = [] ) : void
$content string 模板内容
$vars array 模板变量
$config array 模板参数
return void
    public function display($content, $vars = [], $config = [])
    {
        if ($vars) {
            $this->data = $vars;
        }
        if ($config) {
            $this->config($config);
        }
        $cacheFile = $this->config['cache_path'] . $this->config['cache_prefix'] . md5($content) . '.' . ltrim($this->config['cache_suffix'], '.');
        if (!$this->checkCache($cacheFile)) {
            // 缓存无效 模板编译
            $this->compiler($content, $cacheFile);
        }
        // 读取编译存储
        $this->storage->read($cacheFile, $this->data);
    }

Usage Example

Example #1
0
 public function testDisplay()
 {
     $template = new Template();
     $template->assign('name', 'name');
     $config = ['strip_space' => true, 'tpl_path' => dirname(__FILE__) . '/'];
     $data = ['name' => 'value'];
     $template->display('display', $data, $config);
     $this->expectOutputString('value');
 }
All Usage Examples Of think\Template::display