First, the template inherits:
Assumption: In the View folder
Public module
->base/header/top/footer 4 HTML files
The following base file uses include to introduce the other 3 files, where title uses the block tag, gives a name attribute, and can be used in different templates to redefine the title value .
Block tag, property is main can be, write different content in different template
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0"> <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge"> <title><Blockname= "title">Title</Block></title></Head><Body> <includefile= "Public/header" /> <includefile= "Public/top" /> <Blockname= "Main"></Block> <includefile= "Public/footer" /></Body></HTML>
View Code
The->user module and the UserController.class.php control correspond to the
This is the file that inherits the base
{__nolayout__}<!--force not loading layout -<!--how templates are inherited -<Extendname= "Public/base" /><Blockname= "title">This is the title of the Select</Block><Blockname= "Main"> <Divstyle= "box-shadow:2px 2px 2px Red">This is the Select module</Div></Block>
View Code
After executing the file, you can see that the inheritance succeeds and the title value is also modified
There is also a way to modify the corresponding title value is in the base file,<title>{$title}</title>, with a variable to replace , and then in the corresponding execution of the controller, assign the value to the variable
thinkphp templates inherit and modify title