think\Template::layout PHP Method

layout() public method

设置布局
public layout ( mixed $name, string $replace = '' ) : object
$name mixed 布局模板名称 false 则关闭布局
$replace string 布局模板内容替换标识
return object
    public function layout($name, $replace = '')
    {
        if (false === $name) {
            // 关闭布局
            $this->config['layout_on'] = false;
        } else {
            // 开启布局
            $this->config['layout_on'] = true;
            // 名称必须为字符串
            if (is_string($name)) {
                $this->config['layout_name'] = $name;
            }
            if (!empty($replace)) {
                $this->config['layout_item'] = $replace;
            }
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testFetch()
 {
     $template = new Template();
     $template->assign('name', 'name');
     $config = ['strip_space' => true, 'view_path' => dirname(__FILE__) . DS, 'cache_id' => '__CACHE_ID__', 'display_cache' => true];
     $data = ['name' => 'value'];
     $template->layout('layout')->fetch('display', $data, $config);
     $this->expectOutputString('value');
 }