In the Thinkphp template, the method of using user-defined functions is explained. because it is required by a large job and the time is tight, it is basically no foundation for what to query and what to learn.
I checked the method of using user-defined functions in the Thinkphp template on the Internet, as shown below. this is the case for several websites, but it is really general. please help me explain it.
The built-in template engine supports the use of functions for template variables and the simultaneous use of multiple functions
Note: User-defined functions should be stored in the project application directory/common. php. Here is the key.
Template variable function call format: {$ varname | function1 | function2 = arg1, arg2 ,###}
Note:
{There must be no space between the symbol and the $ symbol, so there is no problem with the space of the following parameter;
### Parameter location of the template variable itself;
Multiple functions are supported, and spaces are supported between functions;
Function shielding is supported. in the configuration file, you can configure a list of disabled functions;
Variable caching is supported. repeated variable strings are parsed several times.
Example:
{$ WebTitle | md5 | strtoupper | substr = 0, 3}
{$ Number | number_format = 2}
{$ Varname | function1 | function2 = arg1, arg2 ,###}
Instance:
The code is as follows:
Function Cate ($ cid ){
$ Cate = D ('Cate ');
$ Cate = $ Cate-> where ('Id = '. $ cid)-> find ();
Return $ Cate ['title'];
}
I want to call this function in the template, so you can write it like this in the template.
{$ Vo. cid | cate ###}
Reply to discussion (solution)
Is it clear about the explanation?
What are your questions?
Just pull the image
Do you think I will ask you clearly?