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

Problem cases of Thinkphp5 template inheritance and replacement

angryTom
angryTom forward
2020-03-16 10:27:06 2756browse

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文件      {block name="title"} 雷小天thinkPHP开发版 {/block}     
{include file="common/nav" /}
{block name="body"} {/block}

The following is index0.html

{extend name="common/base" /} {block name="title"} thinkPHP5 index页 {/block} {block name="body"} 

这里是index body

{/block} {block name="sidebar"}

这里是index sidebar

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