thinkphp template usage and content output instance, thinkphp template _php Tutorial

Source: Internet
Author: User

thinkphp template usage and content output instances, thinkphp templates


The examples in this article describe thinkphp template usage and content output. Share to everyone for your reference. The specific analysis is as follows:

First, the use of templates

A, rules

folder under the template folder [TPL]/with the same name as the module name [index]/file with the same name as the method name [Index].html (. TPL)
Under the Templates folder [tpl]/[Group folder/]/folder with the same name as module names [index]/file with the same name as the method name [Index].html (. TPL)
Under Templates folder [tpl]/[Group folder/][template Theme Folder/]/folder with the same name as module name [index]/file with the same name as the method name [Index].html (. TPL)
The difference here is that the superior file directory design, and some group design and application relationship (foreground and background applications), in the group design template can be divided into theme folders.
Replace the suffix name of the template file (modify the configuration file)
Copy the code as follows: ' Tmpl_template_suffix ' + '. html ',//change template file suffix name

b, how to deal with the template directory hierarchy is too deep, you can create a template name in the TPL folder. HTML Example: index_index.html

1 ' Modify template file directory hierarchy
Copy the code as follows: ' Tmpl_file_depr ' + ' _ ',//Modify the template file directory hierarchy where _ is the underscore in the corresponding template filename.

2, write the template file inside, you can use the newly created template file

C, template theme, is similar to the theme of QQ space, you can dynamically select template theme files.
Copy the code as follows: ' default_theme ' = ' your ',//set Default template theme
You need to create a new your folder under the TPL as the template theme folder, and then create the index folder to establish the index.html

How do I dynamically modify a template theme?

1. Prepare a function in the background, modify the default template item in the config.php file

2. Pass t= theme parameters via URL to modify different templates
Copy the code as follows: ' default_theme ' = ' your ',//set Default template theme
' Tmpl_detect_theme ' =>true,//auto-detect template Theme
' Theme_list ' + ' your,my ',//list of supported templates themes
Access Method Localhost/thinkphp/index.php/index/index?t=you
Localhost/thinkphp/index.php/index/index/t/you
Template theme do not have to close

Second, the output template content

Display method:

No parameters in 1.display
Copy the Code code as follows: $this->display ();//default calling method the same template file
2. Can take parameters
Copy the code as follows: $this->display (specified template file under this module folder);
$this->display (' index2 ');
$this->display (other template files under other folders);
$this->display (' public:error ');//Note that only need to have the public folder under the TPL and the error.html in it, do not need to have the public module, as long as there is this folder can be
$this->display (template file under a folder under other topics);//need to turn on theme support
$this->display (' My:Index:index ');

It is hoped that this article will be helpful to everyone's thinkphp framework design.

http://www.bkjia.com/PHPjc/919269.html www.bkjia.com true http://www.bkjia.com/PHPjc/919269.html techarticle thinkphp template usage and content output instances, thinkphp templates This article describes thinkphp template usage and content output. Share to everyone for your reference. The specific analysis is as follows: First, die ...

  • 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: info-contact@alibabacloud.com 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.