Layout and inheritance of Thinkphp 6.0 template

In this lesson, let's learn about layout methods in templates and template inheritance.


one. template layout


1. By default, the template layout function is not supported and needs to be enabled in the configuration file;
2. In the configuration file view.php, configure the start template layout function;
 

'layout_on' => true, 

3. At this point, execute the template controller in the previous lesson, and you will find that the template layout.html is missing;
4. The default layout file can be changed, and its location and name can be configured;
 

'layout_name' => 'public/layout', 

5. layout.html is responsible for the code part of all common modules, and local content is imported through variables;
6. Use {__CONTENT__} tags similar to magic methods to import non-general content in index.html;

{include file='public/header,public/nav' title='$title'
keywords='关键字!'/}
{__CONTENT__}


7. You can change {__CONTENT__}, as long as it is configured in the configuration file;
 

'layout_item' => '{__REPLACE__}' 

8. Re-emphasis: When retesting, if you change the configuration file, be sure to delete the compiled file under temp and refresh it again;
9. The above mentioned is the first method, the configuration file is downloaded to open the layout, and the second method does not need to be opened Use it directly;
10. First, you must close the first configuration, which I commented out directly, and then use the {layout} tag;
11. Just add the following code at the top of block.html to realize the template layout ;
 

{layout name="public/layout" replace='[__REPLACE__]'}


two. template inheritance


1. Template inheritance is another layout method, and the idea of ​​this layout is more flexible;
2. First, we need to create a base template file of public/base.html, and the file name is optional;

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{$title}</title>
</head>
<body>
</body>
</html>

Guess you like

Origin blog.csdn.net/qq_34820433/article/details/129985782