It is enough to use common labels for variable output, but to complete other control, loop, and judgment functions, you need to use the tag library function of the template engine, all labels in the system's built-in tag library can be directly used without the need to introduce the tag library. # Php/php-tp-historyoutput.html "target =" _ blank "> variable output using common labels is enough, but to complete other control, loop and judgment functions, with the help of the tag library function of the template engine, all the labels in the built-in tag library can be directly used without the need to introduce the tag library.
There are two types of XML tags, including closed tags and open tags. when defining a tag, whether it is a closed tag or an open tag is determined and cannot be used together. for example:
Closed tag:
Open tags:
value
The built-in supported labels and attributes are listed as follows:
Tag name |
Function |
Include attributes |
Include |
Contains External template files (closed) |
File |
Import |
Import resource files (closed, including js css load aliases) |
File, href, type, value, basepath |
Volist |
Loop array data output |
Name, id, offset, length, key, mod |
Foreach |
Array or object traversal output |
Name, item, key |
For |
For loop data output |
Name, from, to, before, step |
Switch |
Branch judgment output |
Name |
Case |
Branch judgment output (must be used with the switch) |
Value, break |
Default |
Output by default (closed must be used together with switch) |
None |
Compare |
Comparison output (including aliases such as eq neq lt gt egt elt heq nheq) |
Name, value, type |
Range |
Output of range judgment (including in notin between notbetween alias) |
Name, value, type |
Present |
Determine whether to assign a value |
Name |
Notpresent |
Determines if no value is assigned |
Name |
Empty |
Judge whether the data is empty |
Name |
Notempty |
Judge whether the data is not empty |
Name |
Defined |
Determine whether a constant is defined |
Name |
Notdefined |
Determines whether a constant is undefined. |
Name |
Define |
Constant definition (closed) |
Name, value |
Assign |
Variable assignment (closed) |
Name, value |
If |
Conditional judgment output |
Condition |
Elseif |
Conditional judgment output (the closure must be used together with the if tag) |
Condition |
Else |
Conditional output (closed for other tags) |
None |
Php |
Use php code |
None |
1. include
You can use the Include tag to Include external template files. the usage is as follows:
Include tags (including external template files) |
Close |
Close tags |
Attribute |
File (required): The template file to be included. variables are supported. |
Example:
1. use the complete file name to include
Format:
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
Format:
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
Format:
For example, the header operation template containing the Public module:
4. module operation templates with other template themes
Format:
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
Format:
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.
[title]
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.
The above is a detailed description of the commonly used built-in tag include in thinkphp. For more information, see PHP Chinese network (www.php1.cn )!