Home >Backend Development >PHP Tutorial >How to use custom functions in Thinkphp templates

How to use custom functions in Thinkphp templates

高洛峰
高洛峰Original
2016-12-01 10:19:471315browse

Note: Custom functions must be placed in the project application directory/common/common.php. Here's the key.

Function calling format of template variables: {$varname|function1|function2=arg1, arg2, ### }

Note: There can be no spaces between

{ and the $ symbol, and there will be no problem with spaces in the following parameters;

### represents the parameter position of the template variable itself;

Supports multiple functions, and spaces are supported between functions;

Supports function shielding function, and a list of prohibited functions can be configured in the configuration file;

Supports variable caching function , repeated variable strings are not parsed multiple times.

Usage example:

{$webTitle|md5|strtoupper|substr=0, 3}

{$number|number_format=2}

{$varname|function1|function2=arg1, arg2, ### }

Example:
Copy code The code is as follows:
function Cate($cid){
$Cate=D('Cate');
$Cate=$Cate->where('id='.$cid)-> find();
return $Cate['title'];
}

If I want to call this function in the template, I can write it like this in the template

{$vo.cid|cate=###}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn