thinkPHP 5 模板繼承
阿新 • • 發佈:2019-01-23
首先要建立一個公共頁面:
以下是(控制器)index.php
<?php
namespace app\admin\Controller;
// use think\Controller;
use think\Db;
use think\Model;
class Index extends Common
{
public function index()
{
return $this->fetch();
}
public function base()
{
return $this->fetch();
}
}
在base.html檔案中<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>{block name="title"}標題{/block}</title> </head> <body>
/**
在{block}新增公共內容
*/
{block name="menu"}選單{/block}
{block name="left"}左邊分欄{/block}
{block name="main"}主內容{/block}
{block name="right"}右邊分欄{/block}
{block name="footer"}底部{/block}
</body>
</html>
在index.html檔案中引用base.html中的內容
{extend name="index/base" /}//如果單單使用這句,index.html將引用base.html裡面的內容;如果要更改裡面某個地方的內容如下所示:
{block name="main"}//這裡新增的內容將是改變主內容{/block}//具體可以參考tp5手冊