The Thinkphp template uses the user-defined function method for explanation.

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.