thinkPHP 5 模板继承

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/toume/article/details/75303786

首先要建立一个公共页面:

以下是(控制器)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手册


猜你喜欢

转载自blog.csdn.net/toume/article/details/75303786
今日推荐