How to use custom functions in Thinkphp templates

高洛峰
Release: 2023-03-02 16:32:01
Original
1259 people have browsed it

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=###}

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!