TP5模板繼承
阿新 • • 發佈:2018-11-15
以下命名都可以根據自己喜好命名!
該圖為以下所需檔案的目錄情況
1.首先新建個控制器
<?php
namespace app\admin\controller;
use think\Controller;
class Test extends Controller
{
public function test2(){
return $this->view->fetch();
}
}
2.在view目錄下新建個繼承的資料夾public,裡面新建testHeader.html、testFoot.html、testBase.html
(1)testHeader.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模板繼承</title>
</head>
<body>
我是頭部
(2)testFoot.html
我是底部
</body>
</html>
(3)testBase.html
{include file='public/testHeader' /} {block name='body'} 我是預設主體 {/block} {block name='address'} 我是預設地址 {/block} {include file='public/testFoot' /}
3.再新建個控制器對應的檢視資料夾Test,並在下面建test2.html
{extend name='public/testBase' /}
{block name='body'}
我是繼承主體
{/block}
{block name='address'}
{__block__}<!--呼叫預設內容-->
{/block}
4.訪問tp5.com/admin/test/test2就能看到效果
OK,大功告成!