没不鸵菩讳草脐釜睦豁啪乓忌
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; class Index extends \think\Controller { public function index() { return $this->fetch(); } }
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\view\index\index.html:
<p>index模板</p>
创建父模板
<!doctype html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> {block name="nav"}导航{/block} {block name="info"}信息列表{/block} {block name="link"}友情链接{/block} </body> </html>
因为父模板中的公共部分可能会在很多地方都要用到
分离父模板的头部和尾部
创建公共的模板文件目录base
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\view\base\header.html:
<!doctype html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body>
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\view\base\footer.html:
</body> </html>
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\view\layoutextend.html:
{include file="base/header" /} {block name="nav"}导航{/block} {block name="info"}信息列表{/block} {block name="link"}友情链接{/block} {include file="base/footer" /}
子模板index.html
{extend name="layoutextend"} {block name="nav"} <ul> <li> <a href="">首页</a> <a href="">关于我们</a> <a href="">公司新闻</a> <a href="">联系我们</a> </li> </ul> {/block} {block name="info"} <ul> <li>欢迎来到萌面人资料铺</li> <li>欢迎来到萌面人资料铺</li> <li>欢迎来到萌面人资料铺</li> <li>欢迎来到萌面人资料铺</li> </ul> {/block} {block name="link"} <a href="http://php.net">php官网</a> <a href="http://thinkphp.cn">thinkphp官网</a> <a href="http://baidu.com">百度</a> {/block}
执行:
如枚懦钉梧挽寇烂承邦汕谴惟