Note: The custom function should be placed in the project application directory/common/common.php. Here is the key.
function call format for template variable: {$varname |function1|function2=arg1,arg2,###}
Description
There can be no spaces between {and $ symbols, there is no problem with the space behind the arguments;
# # #表示模板变量本身的参数位置;
Supports multiple functions and supports spaces between functions;
Support function masking function, in the configuration file can be configured to prohibit the use of the list of functions;
The variable cache function is supported, and the repeating variable string is not resolved multiple times.
Examples of Use:
- {$webTitle| MD5| Strtoupper| substr=0,3}
- {$number| Number_format=2}
- {$varname| Function1| function2=arg1,arg2,# # #}
Copy Code
Instance:
Copy the code code as follows:
- function Cate($cid) {
- $Cate=D(' Cate ');
- $Cate=$Cate, where(' id= '. $cid),find();
- return $Cate[' title '];
- }
Copy Code
I want to call this function in the template, which I can write in the template.
- {$vo. CID| Cate=# # #}
Http://www.thinkphp.cn/topic/1553.html
Ways to use custom functions in thinkphp templates