mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
修正block标签的bug
This commit is contained in:
@@ -217,20 +217,20 @@ class Template
|
|||||||
* 设置布局
|
* 设置布局
|
||||||
* @access public
|
* @access public
|
||||||
* @param mixed $name 布局模板名称 false 则关闭布局
|
* @param mixed $name 布局模板名称 false 则关闭布局
|
||||||
* @return void
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function layout($name)
|
public function layout($name)
|
||||||
{
|
{
|
||||||
if (false === $name) {
|
if (false === $name) {
|
||||||
// 关闭布局
|
// 关闭布局
|
||||||
$this->config['layout_on'] = false;
|
$this->config['layout_on'] = false;
|
||||||
return $this;
|
} else {
|
||||||
}
|
// 开启布局
|
||||||
// 开启布局
|
$this->config['layout_on'] = true;
|
||||||
$this->config['layout_on'] = true;
|
// 名称必须为字符串
|
||||||
// 名称必须为字符串
|
if (is_string($name)) {
|
||||||
if (is_string($name)) {
|
$this->config['layout_name'] = $name;
|
||||||
$this->config['layout_name'] = $name;
|
}
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -524,20 +524,22 @@ class Template
|
|||||||
$replace = str_replace($baseBlocks[$key]['begin'] . $baseBlocks[$key]['content'] . $baseBlocks[$key]['end'], $blocks[$key]['content'], $replace);
|
$replace = str_replace($baseBlocks[$key]['begin'] . $baseBlocks[$key]['content'] . $baseBlocks[$key]['end'], $blocks[$key]['content'], $replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 带有{__block__}表示与所继承模板的相应标签合并,而不是覆盖
|
if (isset($blocks[$name])) {
|
||||||
$replace = !isset($blocks[$name]) ? $replace : str_replace(['{__BLOCK__}', '{__block__}'], $replace, $blocks[$name]['content']);
|
// 带有{__block__}表示与所继承模板的相应标签合并,而不是覆盖
|
||||||
if (!empty($val['parent'])) {
|
$replace = str_replace(['{__BLOCK__}', '{__block__}'], $replace, $blocks[$name]['content']);
|
||||||
// 如果不是最顶层的block标签
|
if (!empty($val['parent'])) {
|
||||||
$parent = $val['parent'];
|
// 如果不是最顶层的block标签
|
||||||
if (isset($blocks[$parent])) {
|
$parent = $val['parent'];
|
||||||
$blocks[$parent]['content'] = str_replace($blocks[$name]['begin'] . $blocks[$name]['content'] . $blocks[$name]['end'], $replace, $blocks[$parent]['content']);
|
if (isset($blocks[$parent])) {
|
||||||
|
$blocks[$parent]['content'] = str_replace($blocks[$name]['begin'] . $blocks[$name]['content'] . $blocks[$name]['end'], $replace, $blocks[$parent]['content']);
|
||||||
|
}
|
||||||
|
$blocks[$name]['content'] = $replace;
|
||||||
|
$children[$parent][] = $name;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
$blocks[$name]['content'] = $replace;
|
|
||||||
$children[$parent][] = $name;
|
|
||||||
} else {
|
|
||||||
// 替换模板中的block标签
|
|
||||||
$extend = str_replace($val['begin'] . $val['content'] . $val['end'], $replace, $extend);
|
|
||||||
}
|
}
|
||||||
|
// 替换模板中的block标签
|
||||||
|
$extend = str_replace($val['begin'] . $val['content'] . $val['end'], $replace, $extend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$content = $extend;
|
$content = $extend;
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ EOF;
|
|||||||
'view_path' => dirname(__FILE__) . '/',
|
'view_path' => dirname(__FILE__) . '/',
|
||||||
];
|
];
|
||||||
$data = ['name' => 'value'];
|
$data = ['name' => 'value'];
|
||||||
$template->display('display', $data, $config);
|
$template->layout('layout')->display('display', $data, $config);
|
||||||
$this->expectOutputString('value');
|
$this->expectOutputString('value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user