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; } /** * 配置模板引擎. * @param array $config 参数 * @return $this */ public function config(array $config) { $this->driver()->config($config); return $this; } /** * 解析和获取模板内容 用于输出. * @param string $template 模板文件名或者内容 * @param array $vars 模板变量 * @return string * @throws \Exception */ public function fetch(string $template = '', array $vars = []): string { return $this->config([ 'view_suffix' => 'html', ])->getContent(function () use ($vars, $template) { $this->engine()->fetch($template, array_merge($this->data, $vars)); }); } /** * 解析和获取模板内容 用于输出. * @param string $template 模板文件名或者内容 * @param array $vars 模板变量 * @return string * @throws \Exception */ public function fetchJS(string $template = '', array $vars = []): string { return $this->config([ 'view_suffix' => 'js', ])->getContent(function () use ($vars, $template) { $this->engine()->fetch($template, array_merge($this->data, $vars)); }); } }