Home  >  Article  >  PHP Framework  >  Problem cases of Thinkphp5 template inheritance and replacement

Problem cases of Thinkphp5 template inheritance and replacement

angryTom
angryTomforward
2020-03-16 10:27:062761browse

This article introduces the problem cases of Thinkphp5 template inheritance and replacement. I hope it will be helpful to friends who are learning ThinkPHP!

Problem cases of Thinkphp5 template inheritance and replacement

Thinkphp5 template inheritance and replacement problem case

Common inheritance problem under the same module, here is the index module as an example

Problem cases of Thinkphp5 template inheritance and replacement

Under the index module, I have my own common and module main view folder index, so I inherited my own base.html in index0 like this

(Recommended tutorial: thinkphp tutorial)

//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>

The following is 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}

I have redefined the title in the index0.html file, and all the final titles are thimkPHP5 index page, but it is worth noting that my footer content is index_22{__block__}, and {__block__} refers to the default value footer at the same position in the template base.html, and all the final footer content is the index_22 default value footer.

The above is inheritance under the same module, and there is another inheritance that inherits the common module. Here, the view/index.html under the idnex module inherits the base.html file under the view under the common module as an example.

Problem cases of Thinkphp5 template inheritance and replacement

Different modules have different inheritance methods. Here, the inheritance method under the common module is: {extend name="common@base" /}, and under the same module Inheritance is:

{extend name="common/base" /}. Some requirements also need to inherit other templates in the base.html file, so you can inherit it in base.html like this: {include file="common@header" /} This means inheriting the view/header.html file under common

PHP Chinese website, a large number of MySQL video tutorials, welcome to learn!

The above is the detailed content of Problem cases of Thinkphp5 template inheritance and replacement. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.100txy.com. If there is any infringement, please contact admin@php.cn delete