ThinkPHP built-in template engine usage summary. The built-in ThinkPHP template engine is an innovative XML compilation template engine. the following uses a case to share the usage of common template labels of the built-in ThinkPHP template engine, the built-in ThinkPHP template engine is an innovative XML compilation template engine. the following uses a case to share the usage of common template labels of the built-in ThinkPHP template engine, including variable output, loop, judgment, comparison, etc. These are basic usage and cannot include all the tags and features of the built-in ThinkPHP template engine.
(1) The following is the source code of the controller IndexAction class.
1,'name'=>'ThinkPHP','email'=>'liu21st@gmail.com'); $this->assign('vo',$vo); $obj = (object)$vo; $this->assign('obj',$obj); $this->assign('array',array(5,260,13,7,40,50,2,1)); $this->assign('num1',6); $this->assign('num2',2); $this->assign('num',6); $this->display(); }} ?>
(2) The following demonstrates the basic usage of some variables, constants, and arrays assigned to the template by the controller.
Universal variable output
Num1: {$ num1}
Object output
Id: {$ obj: id}
Name: {$ obj: name}
Array output
Id: {$ vo ['id']}
Name: {$ vo ['name']}
Automatic array and object output judgment
Id: {$ vo. id}
Name: {$ vo. name}
System constant output (the system constant does not need to be assigned a value in the controller)
{$ Think. now | date = 'Y-m-d H: I: S ',###}
{$ Think. server. PHP_SELF}
{$ Think. session. name}
Use a function for the variable (here it can be a built-in function or a custom function)
{$ Vo. name | strtolower | ucwords}
Foreach output
{$ Key }:{ $ item}
The following example uses the cyclic tag, Switch tag, and comparison tag.
[{$ I}]
Even row
Odd line
{$ Val} is greater than 5
{$ Val} is greater than 15
{$ Val} is less than 10
Data {$ val}
Data {$ val}
Data {$ val}
Other data is {$ val}
The output result is similar:
[1] The length of an odd number of rows 5 less than 10 is 1
[2] an even number of rows with 260 greater than 5 260 greater than 15 length is 3
[3] The length of an odd row 13 is 2 if it is greater than 5
[4] an even number of rows 7 greater than 5 7 less than 10 length is 1
[5] an odd number of rows with 40 greater than 5 40 greater than 15 length is 2
[6] An even row with 50 greater than 5 50 greater than 15 length is 2
[7] The length of odd line 2 less than 10 is 1
[8] The length of an even row 1 less than 10 is 1
Comparison labels of the built-in ThinkPHP template engine
Greater than 3
Less than 3
The output result is similar:
Greater than 3
Less than 3
Condition judgment
{$ Num} is greater than 5
{$ Num} is greater than 3
Others {$ num}
The output result is similar:
6> 5
Articles you may be interested in
- The last record of the volist loop in the thinkphp Template
- Summary of common system variables in Thinkphp templates
- How to set the jump wait time for the thinkphp page jump (successerror)
- Summary of query techniques in ThinkPHP
- Complete parsing of Thinkphp internal function ADSLCFUI shortcuts
- Thinkphp method for disabling caching
- Php Statistics Search engine access records
- Thinkphp prints the last SQL statement
...