您的位置 首页 技术

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

本篇文章介绍了Thinkphp5模板继承和替换的问题案例,希望对学习ThinkPHP的朋友有帮助! Thinkphp5模板继承和替换的问题案例 同一个模块下的common继承问题,…

本篇文章介绍了Thinkphp5模板继承和替换的问题案例,希望对学习ThinkPHP的朋友有帮助!

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

同一个模块下的common继承问题,这里于index模块为例

微信截图_20200316101141.png

在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文件为例

2.png

不同的模块继承方式也不同了,这里继承common模块下的继承方式为:{extend name="common@base" /},而在同模块下的继承是:

{extend name="common/base" /}。而有些需求在base.html文件中还需要继承其他的模板,那么在base.html中可以这样继承: {include file="common@header" /}这个意思就是继承common下的view/header.html文件

PHP中文网,大量MySQL视频教程,欢迎学习!

以上就是Thinkphp5模板继承和替换的问题案例的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/51866.html

为您推荐

返回顶部