<?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.htmlphp
{extend name="public\base"} {block name="body"} {__block__} //這部分是引用模板中的內容 <h2>我是新內容</h2> {/block}
index\view\public\header1.htmlhtml
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h2 style="color: red;">我是繼承模板頭部</h2>
index\view\public\footer.htmlapp
<h2 style="color: green;">我是繼承模板底部</h2> </body> </html>
index\view\public\base.htmlfetch
{include file="public/header1"} {block name="body"} 我是模板內容 {/block} {include file="public/footer"}
這個是用於繼承的模板this