thinkphp5.1学习过程十一 ——模板继承

谁说胖子不能爱 提交于 2019-12-05 03:54:30
<?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.html

{extend name="public\base"}
{block name="body"}
{__block__}  //这部分是引用模板中的内容
<h2>我是新内容</h2>
{/block}

index\view\public\header1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2 style="color: red;">我是继承模板头部</h2>

index\view\public\footer.html

<h2 style="color: green;">我是继承模板底部</h2>
</body>
</html>

index\view\public\base.html

{include file="public/header1"}
{block name="body"}
我是模板内容
{/block}
{include file="public/footer"}

这个是用于继承的模板

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!