---
title: "TP5 模板继承"
author: "onestopweb"
date: "2017-07-24T16:11:15Z"
tags: []
categories: ["编程语言"]
slug: "tp5"
draft: false
lastmod: "2017-07-24T16:11:15Z"
id: 2386628
url: "https://onestopweb.iteye.com/blog/2386628"
---

application\\index\\controller\\Index.html

```
<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    public function base ()
    {
        return $this->fetch();
    }
}
```

 

application\\index\\view\\index\\index.html

```
{extend name="index/base" /}

{block name="title"}
标题2
{/block}
{block name="right"}
阅谁问君诵，水落清香浮。
{/block}

{block name="footer"}
{__block__}@Onestopweb 版权所有
{/block}
```

 

application\\index\\view\\index\\base.html

```
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>{block name="title"}标题{/block}</title>
</head>
<body>
{block name="menu"}菜单{/block}
{block name="left"}左边分栏{/block}
{block name="main"}主内容{/block}
{block name="right"}右边分栏{/block}
{block name="footer"}底部{/block}
</body>
</html>
```

 

注意：{\_\_block\_\_}

效果图：  
![](http://dl2.iteye.com/upload/attachment/0126/2206/da64869c-659c-343c-8126-a9e376108cfe.jpg)