ThinkPHP attracts the header template. the tags in the template are not parsed.

Source: Internet
Author: User
ThinkPHP introduces the header template, and the labels in the template are not parsed. Hello everyone: When I first started using TP, I encountered a problem. The problem is probably like this: The website is divided into the header, content, and bottom. The header is a navigation menu. I wrote the template file header.html. when the index file on the homepage is introduced into the he thinkPHP header template, the labels in the template are not parsed.
Hello everyone:
When I first started using TP, I encountered a problem like this:
The website is divided into the header, content, and bottom.
The header is a navigation menu. the template file is header.html.
When the first page indexfile is imported to header.html, the dynamic content in the header is not displayed.
Localhost/index. php/Common/header (I defined the header method in commonAction. class. php) can be displayed. It indicates that index only introduces static html files and is not parsed? How can this problem be solved? thank you!
------ Solution --------------------
For example, if you load index. php on the home page, the corresponding index must be loaded. Html template. if it has been determined that the static header can be loaded in this case, let's look at your index. Is there any assign () for the data in the header in the index () method in php (),
------ Solution --------------------
No ~, You define a parent class and write some common methods in it. this class inherits the action, which includes overwriting the display () method of tp, then, you can call the header class in this method and the methods in other controllers will automatically load the header as long as you use this display ~ Do you understand?
------ Solution --------------------
Is there a syntax error. Troubleshoot one by one

You can use the Include tag to Include external template files. the usage is as follows:

Include tags (including external template files)
Close tags
File (required): The template file to be included. variables are supported.


1. use the complete file name to include


For example:

In this case, the template file name must contain a suffix. When using a complete file name, note that a file contains a server rather than a URL. that is to say, the file parameter is written in the server path, if the relative path is used, it is based on the entry file location of the project.


2. include other operation template files of the current module


For example, import the read operation template below the current module:

The operation template does not require a suffix.


3. operation templates containing other modules


For example, the header operation template containing the Public module:


4. module operation templates with other template themes


For example, the read operation template of the User module that contains the blue topic:


5. use variables to control the template to be imported


For example

You can assign different values to $ tplName to include different template files. the usage of variable values is the same as that in the preceding example.


No matter how you Include an external template, the Include tag supports parameter input when the file is included. for example, the following example imports the title and keywords variables when the header template is included:

You can use the var1 and var2 variables in the included header.html file.



Note: Due to the characteristics of template parsing, the template is parsed from the entry template. if the external template is changed, the template engine does not re-compile the template unless it is in debugging mode or the cache has expired. If an external template file is modified in deployment mode, clear the cache Directory of the module. Otherwise, the template cannot take effect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.