Thinkphp introduced header template, the label inside the template does not parse
Hello everyone:
Starting with TP, there is a problem, the problem is probably this:
The website is divided into head, Content section and bottom.
The head is mainly a navigation menu, template file I write for header.html
When the index file is introduced into header.html, the dynamic content of the header is not displayed.
The use of Localhost/index.php/common/header (I defined the header method in commonAction.class.php) can be displayed. Description index introduced only static HTML files, and did not parse? How to solve, thank you all!
------Solution--------------------
For example, if you keep loading the homepage index.php, then it is definitely loading the corresponding index. HTML template, if you have determined that this situation is can be loaded into the static header, then look at you at index. PHP inside the index () method inside whether there is no data inside the header assign (),
------Solution--------------------
No, you define a parent class, which writes some common methods that inherit the action, including the display () method that overrides the TP, and then call the header class in this method so that the other controller can use the display () to automatically load the header~, you understand?
------Solution--------------------
Is there a grammatical error? Troubleshooting
You can use the include tag to include external template files, using the following methods:
Include tags (including external template files)
Closed
Closed label
Property
File (required): template file to include, support variable
Example:
1. Use the full file name to include
Format:
For example:
In this case, the template file name must contain a suffix. When using the full file name, it is important to note that the file contains a server-side inclusion, not a URL address, that is, the file parameter is the server-side path, if you use a relative path, it is based on the entry file location of the project.
2. Other action template files containing the current module
Format:
For example, import the Read action template under the current module:
The action template does not need to have a suffix.
3. Action template with other modules
Format:
For example, the header action template that contains the public module:
4. Module action template with other template themes
Format:
For example, the Read action template for the user module that contains the blue theme:
5. Use variables to control the template to be imported
Format:
For example
assigning different values to $tplname can contain different template files, and the values of the variables are used the same as the previous usage.
Regardless of the way you use the external template, the include tag supports passing in parameters at the same time as the include file, for example, in the following example we passed the title and keywords variables when we included the header template:
You can use the var1 and VAR2 variables in the included Header.html file, method
<title>[Title]</title>
Note: Because of the characteristics of template parsing, parsing starts from the portal template, and if the external template changes, the template engine does not recompile the template unless in debug mode or the cache has expired. If the included external template file is modified in deployment mode, the cache directory of the module needs to be emptied, otherwise it will not take effect.