<?php
namespace app\index\controller;
use think\Controller;
class Demo8 extends Controller
{
public function test1()
{
//
return $this->view->fetch();
}
}
view/demo8/test1.html
<h2>我是网站的主体部分布局</h2>
view/head.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2 style="color: red;">我是网站的头部</h2>
view/footer.html
<h2 style="color: green;">我是网站的底部</h2> </body> </html>
view/layout.html
{include file="head"}
{__CONTENT__}
{include file="footer"}
在template.php配置文件中增加
//开启全局模板布局 'layout_on'=>true, //全局模板布局文件名 'layout_name'=>'layout',
开启全局模板布局,模板布局文件名设置以后,模板html的文件名要一致,本例中都使用了layout
如果不使用全局模板布局,
view/demo8/test1.html可以使用{include file="head"}来引用模板