您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Thinkphp5模板继承和替换的问题案例

2025/9/12 12:05:26发布18次查看
本篇文章介绍了thinkphp5模板继承和替换的问题案例,希望对学习thinkphp的朋友有帮助!
thinkphp5模板继承和替换的问题案例
同一个模块下的common继承问题,这里于index模块为例
在index模块下有自己的common和模块主视图文件夹index,那么我index0里面继承了自己的base.html是这样的
(推荐教程:thinkphp教程)
//base.html文件<!doctype html><html> <head> <meta charset="utf-8"> <title> {block name="title"} 雷小天thinkphp开发版 {/block} </title> <link rel="stylesheet" type="text/css" href="__css__/style.css"> <link rel="stylesheet" type="text/css" href="__layui__/css/layui.css"> <script type="text/javascript" src="__layui__/layui.js"></script> </head> <body> <div class="wrap"> <!-- 头部 --> <div class="header"> {include file="common/nav" /} </div> <!-- 中部 --> <div class="main"> <!-- 边栏 --> <div class="body"> {block name="body"} {/block} </div> <!-- 内容 --> <div class="sidebar"> {block name="sidebar"} {/block} </div> </div> <!-- 尾部 --> <div class="footer"> {block name="footer"} 默认值footer {/block} </div> </div> </body></html>
下面是index0.html
{extend name="common/base" /}{block name="title"} thinkphp5 index页{/block}{block name="body"} <h1>这里是index body</h1>{/block}{block name="sidebar"} <h1>这里是index sidebar</h1>{/block}{block name="footer"} index_22{__block__}{/block}
我在index0.html文件中有重新定义title,所有最后的title是thimkphp5 index页,但值得注意的是我footer内容是index_22{__block__},而{__block__}指的是在模板base.html中同位置的默认值footer,所有最后footer的内容是index_22默认值footer。
以上是同模块下的继承,还有一种是继承common模块的继承,这里于idnex模块下的view/index.html继承common模块下view下的base.html文件为例
不同的模块继承方式也不同了,这里继承common模块下的继承方式为:{extend name=common@base /},而在同模块下的继承是:
{extend name=common/base /}。而有些需求在base.html文件中还需要继承其他的模板,那么在base.html中可以这样继承:  {include file=common@header /}这个意思就是继承common下的view/header.html文件
,大量mysql视频教程,欢迎学习!
以上就是thinkphp5模板继承和替换的问题案例的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product