<?php
namespace app\index\controller;
use think\Controller;
class Demo8 extends Controller
{
public function test1()
{
//
return $this->view->fetch();
}
//模板继承
public function test2()
{
//
return $this->view->fetch();
}
}
index\view\test2.html
{extend name="public\base"}
{block name="body"}
{__block__} //这部分是引用模板中的内容
<h2>我是新内容</h2>
{/block}
index\view\public\header1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2 style="color: red;">我是继承模板头部</h2>
index\view\public\footer.html
<h2 style="color: green;">我是继承模板底部</h2> </body> </html>
index\view\public\base.html
{include file="public/header1"}
{block name="body"}
我是模板内容
{/block}
{include file="public/footer"}
这个是用于继承的模板