模板赋值与模板内容过滤与替换技术
控制器代码:
public function replace(){
$this->view->name = 'Lin';
$this->view->salary = '8000';
$filter = function ($content){
return str_replace('Lin','GG', $content);
};
return $this->filter($filter)->fetch();
}
view视图replace代码:
我的姓名:{$name}
我的工资:{$salary}
模板动态布局与模板继承技术
模板动态布局
在view视图下新建一个layout.html,代码:
{include file="public/header" /}
{__CONTENT__}
{include file="public/footer" /}然后在控制器Users代码:
public function layout_list(){
/*
* 1.全局配置
*config/temaplate.php
* //模板布局配置 'layout_on' =>true, 'layout_name' => 'layout'
* 2.模板表签进行配置
*
* 3.动态配置
*/
//开启布局
$this->view->engine->layout(true);
return $this->view->fetch('layout');
}最后view/layout_list.html代码:
{//layout name="layout" /}
{//__NOLAYOUT__}<!--关闭模板-->
<div class="main">主体</div>模板继承技术
首先在view视图下新建一个base.html 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模板继承</title>
</head>
<body>
{block name="header"}
{include file="public/header" /}
{/block}
{block name="main"}主体部分{/block}
{block name="footer"}
{include file="public/footer" /}
{/block}
</body>
</html>控制器代码:
public function block(){
return $this->view->fetch();
}view\Users\block.html 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模板继承</title>
</head>
<body>
{extend name="base" /}
{//将main区块进行重写}
{block name="main"}
{__block__} 部分 <!--显示父区块的内容-->
{/block}
</body>
</html>