View 1, template comments in thinkphp
In the actual project development, the annotation function is often used, and if it is a thinkphp framework, it can be commented in the template file as follows:
{//comment content}: single-line comment
{/* Comment content */}: Multiline Comment
?
Example code:
Running the above code shows that the template comment in the thinkphp framework belongs to the service-side comment and does not display the output in the client browser.
2. Fetch template Content
In the actual project development, if we just want to get the template content but not output, then this time can consider using the fetch method to implement.
$this->fetch (): ① loading template ② substitution variable
$this->display (): ① load template ② replace variable ③ output template content
?
Example code:
3. Variable output
In the thinkphp template engine, you can use the Assign method to assign a variable to a template file and output it, which can be an ordinary variable, an array variable, an object variable, or a variable type.
?
1) Common variables
In the template, access to it can be achieved through the {$ variable name}:
?
2) Array variables
① One-dimensional arrays
You can display output in a template in the following ways:
② Two-dimensional arrays
In the template file, you can access it in the following ways:
?
3) Object variables
In the template file, you can access it in the following ways:
4. System Variables
- $Think. Server: $_server[]
- $Think. Get???? : $_get[]
- $Think. Post: $_post[]
- $Think. Request: $_request[]
- $Think. Cookie: $_cookie[]
- $Think. Session: $_session[]
- $Think. config: Reading configuration information from a configuration file
?
Example code:
Operation Result:
5. Using function (variable adjuster)
Main function: Implement the format operation of the variable, basic syntax:
{$name |fn1|fn2=arg1,arg2,###}
Special note: In the use of functions, it has a special form: # # #代表当前变量本身
?
Example code:
6. Default value
In the actual project development, a variable is often judged, if it is empty, it will not show anything, but so its experience is not very friendly, so in order to solve this problem, you may want to consider using the default values to set:
{$ variable |default= "default value"}
7. Operators
In some template engines such as smarty, it is not possible to directly participate in mathematical operations. However, in the thinkphp template engine, it is the basic syntax that allows for direct mathematical operations:
- +???????? {$a + $b}
- -???????? {$ab}
- *???????? {$a * $b}
- /???????? {$a/$b}
- %???? {$a% $b}
- ++???? {$a + +} or? {+ + $a}
- --???? {$a--}? or {--$a}
Example code:
In the template page, you can use operators to perform mathematical operations on the above two variables:
View two in thinkphp