1. Include Files
Usage scenarios: For example, when we write the layout of the page, it is possible that each page has the same head and foot, and it is too troublesome to set each page separately. You can use the Include files at this point.
First check the configuration file to see where our theme directory is, we can view it in the core profile: ' Default_theme ' + ' default ', so my is under the default theme. It is also said in:
Home/view/default/user below.
(1) We first create two file header.html/footer.html under the default folder, respectively:
Header.html
<! DOCTYPE HTML public '-//w3c//dtd HTML 4.01 strict//en ' HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD ' >
<meta http-equiv= ' content-type ' content= ' text/html; Charset=utf-8 ' >
<title><block name= "title" > Insert title here </block></title>
<body>
<div id= "Header" > here is header file </div>
Footer.html
<div id= "Footer" > here is footer file </div>
</body>
(2) and then in the use of the time to invoke the separate, do not like index.html
<include file= ' Public/header '/>
It worked
<include file= ' Public/footer '/>
2. Template inheritance
Using the file inclusion method described above, it is found that the <title></title> value of each page is the same and is obviously inappropriate. How to solve it? This is used for template inheritance
(1) First create a basic.html in the public/directory, the content is as follows (this is the basic web framework)
<! DOCTYPE HTML public '-//w3c//dtd HTML 4.01 strict//en ' HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD ' >
<meta http-equiv= ' content-type ' content= ' text/html; Charset=utf-8 ' >
<title><block name= "title" > Insert title here </block></title>
<body>
<include file= "Public/header"/><!--to include the contents of the header.html file
<block name= "main" ></block><!--to include footer.html file contents
<include file= "Public/footer"/>
</body>
(2) It is also necessary to change the content of header.html,footer.html (because the basic public part of the page is already included in the underlying file basic.html)
Header.html
<div id= "Header" > here is header file </div>
Footer.html
<div id= "Footer" > here is footer file </div>
(3) How to use index.html/select.html
Index.html
<extend name= "public/basic.html" >
<block name= "title" >index Header </block>
<block> Web Theme content (that is, content in body) </block>
Select.html
<extend name= "public/basic.html" >
<block name= "title" >select.html Header </block>
<block> Web Theme content (that is, content in body) </block>
3. Template layout
Thinkphp's template engine has built-in support for layout templates, which makes it easy to implement template layouts and layout nesting functions. There are three ways of layout:
Create a layout.html file under public/
<! DOCTYPE HTML public '-//w3c//dtd HTML 4.01 strict//en ' HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD ' >
<meta http-equiv= ' content-type ' content= ' text/html; Charset=utf-8 ' >
<title> Insert title here </title>
<body>
<include file= "Public/header"/>
{__content__}
<include file= "Public/footer"/>
</body>
(1) Global configuration method
A. First we need to configure the core configuration file config.php
Open the template layout feature and specify the base page
' Layout_on ' =>true,
' Layout_name ' = ' public/layout ',
B. This layout.html page template is used when we create a new HTML file under view/user/
(2) If we do not want to open the template configuration function, only use the default template on this page, you can use the tag mode
Sub-template Introduction Template Base page
<layout name= "Public/layout"/>
(3) Layout control layouts
This method is used directly in the controller
UserController.class.php
Introduce the specified base page
Public Function index () {
Layout (' Public/layout ');
Layout (false); Shut down
}
thinkphp3.2.3 about the use of Templates twos