thinkphp template usage and content output instance _php

Source: Internet
Author: User
Keywords thinkphp template usage content output
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)

The code is 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

The code is 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.

The code is 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

The code is 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

The code is as follows:

$this->display ();//default calling method the same template file


2. Can take parameters

The code is 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.

  • 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: 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.