Methods that use custom functions in Thinkphp templates
- 2020-05-26 07:56:12
- OfStack
Note: custom functions are placed in the project application directory /common/ common.php. Here's the key.
Function call format of template variable: {$varname|function1|function2=arg1, arg2, ###}
Description:
There can be no Spaces between {and $; Spaces for the following arguments are fine.
### indicates the parameter location of the template variable itself;
Support multiple functions, support space between functions;
Support function masking, in the configuration file can be configured to prohibit the use of the list of functions;
Support for variable caching, repeating variable strings without multiple parsing.
Examples to use:
{$webTitle | md5 | strtoupper | substr = 0, 3}
{$number|number_format=2}
{$varname|function1|function2=arg1, arg2, ###}
Example:
I want to call this function in my template and I can write it like this in my template
{$vo.cid|cate=###}
Function call format of template variable: {$varname|function1|function2=arg1, arg2, ###}
Description:
There can be no Spaces between {and $; Spaces for the following arguments are fine.
### indicates the parameter location of the template variable itself;
Support multiple functions, support space between functions;
Support function masking, in the configuration file can be configured to prohibit the use of the list of functions;
Support for variable caching, repeating variable strings without multiple parsing.
Examples to use:
{$webTitle | md5 | strtoupper | substr = 0, 3}
{$number|number_format=2}
{$varname|function1|function2=arg1, arg2, ###}
Example:
function Cate($cid){
$Cate=D('Cate');
$Cate=$Cate->where('id='.$cid)->find();
return $Cate['title'];
}
I want to call this function in my template and I can write it like this in my template
{$vo.cid|cate=###}