Normal output Output the variables in the template in the following format: {$Variable name} Example:
Default output If the output template variable has no value, but we need to assign a default value when displaying, we can use the default syntax to display a value by default. Format: {$variable|default="default value"} example:
Use function Using functions with template variables The template engine supports formatting of output variables, that is, using functions, and supports multiple functions. Format: {$variable|function1|...|functionn=parameter1,...,parametern,###} The function executes the variables from left to right. Function 1 is executed first. After the result is obtained, it is used as a parameter and then function 2 is executed, and so on. By default, the execution result is used as the first parameter of the next function. Example:
The actual execution result is equivalent to: If the variable or the result of the previous function execution is not the first parameter of the function or the next function, then the locator "###" needs to be used: {$userinfo["regdate"]|date="Y-m-d H:i",###} The actual execution result is equivalent to:
Tips There is no limit on the number of functions you can use with variables, but the exit and echo functions are disabled by default to prevent corrupting template output. For specific configuration of disabled functions, please refer to "ThinkPHP System Configuration". Template uses functions directly Template files also support shortcut methods for calling functions directly without passing template variables, including two methods: 1. Execute the function and output the return value Format: {:function} example:
2. Execute the function but not output Format: {~function} example:
The above two methods also support passing in template variables as parameters of the function. System variable output System variables include: server, session, post, get, request, cookie, env. The output of system variables does not need to be assigned to a template variable in advance. The output of system variables begins with $Think., and the use of functions is still supported. Example:
System constant output Use $Think.const to output system constants. Example:
Configuration parameter output Use $Think.config to output the project's configuration parameter values. Example:
The output value is the same as the return result of C('DB_PREFIX'). Quick output In order to make the template definition more concise, the system also supports some commonly used variable output shortcut tags, including:
Tips Quick output does not support the use of functions In order to make the template more readable, it is not recommended to use the shortcut output method |