Template engine usage details: including public templates

Source: Internet
Author: User
ThinkPHP has a built-in XML-based compiling template engine. This article describes the built-in labels in depth. if you are using a third-party template engine such as Smarty, ignore it. The output of variables is described in detail in the quick start variable output. the output judgment, loop, and control of variables are described later, thinkPHP, including public templates and resource files, has a built-in XML-based compilation template engine. This article introduces its built-in labels in depth, if you are using a third-party template engine such as Smarty, ignore it.
The output of variables is described in detail in the quick start variable output. The following describes the output judgment, loop and control of variables, as well as public templates and resource files. Include public templates [-more-] include tags use include tags to include public templates in the current template, such as common headers and footer public templates. The most common attribute of include tags is file, however, it supports different usage. The basic method is similar to the commonly used template rendering method display. For example:
Contains the header template under the Public Directory
The copy code contains the menu template under the current template directory.
Copy the code. if you currently use the multi-template topic function, you can also include templates for other topics.
Copy the code to include the User/read template file under the blue template topic. the depth of the template supported by the include tag can only reach the operation level. that is to say, the default template structure of ThinkPHP is as follows: Topic/module/Operation. Template suffixWhen using the preceding method to include a template, you do not need to specify the template suffix for the file attribute. if your template structure is not a standard structure, you can use the method to include the complete template file:
Copy the code. if you specify the template file suffix in the file attribute, it will be considered as a rule that contains the complete template. if you use the relative path inclusion, the current start directory should be the location of the project entry file.
You can also use the variable method:
Copy the code but do not recommend the variable calling method, because the template engine compilation feature will be cached after compilation. In addition to the file attribute, the include tag for parameter transfer also supports passing some simple parameters and passing them directly to the template file. for example, we include a header file, to dynamically specify the webpage title and keyword information in the template file, you can use:
Copy the code. when we include the header public template, we also input the title and keywords parameters. let's take a look at how the header template file receives these parameters:
  1. [Title]
Copy [title] and [keywords] in the code template file to replace the parameters passed in the include tag. The include tag can contain multiple templates starting from version 3.1. for example:
The copy code can also support different methods of inclusion mixing, for example:
Copy code nesting include template include tags support nesting, for example, we can re-include another public template in the header public template file:
  1. [Title]
Copy the code and theoretically do not limit the nesting layers, as long as you do not need to avoid loop nesting. The summary include tag can simplify duplicate template writing to a certain extent and facilitate synchronous modification. if the public template file is changed but the current master template file is not changed, the template cache will not be automatically updated. unless you have set the template cache validity period, the template cache will be automatically updated after the cache expires.

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.