Ways to use custom functions in thinkphp templates

Source: Internet
Author: User

Note: The custom function should be placed in the project application directory/common/common.php. Here is the key.

function call format for template variable: {$varname |function1|function2=arg1,arg2,###}

Description
There can be no spaces between {and $ symbols, there is no problem with the space behind the arguments;

# # #表示模板变量本身的参数位置;

Supports multiple functions and supports spaces between functions;

Support function masking function, in the configuration file can be configured to prohibit the use of the list of functions;

The variable cache function is supported, and the repeating variable string is not resolved multiple times.

Examples of Use:

  1. {$webTitle| MD5| Strtoupper| substr=0,3}
  2. {$number| Number_format=2}
  3. {$varname| Function1| function2=arg1,arg2,# # #}
Copy Code

Instance:
Copy the code code as follows:

  1. function Cate($cid) {
  2. $Cate=D(' Cate ');
  3. $Cate=$Cate, where(' id= '. $cid),find();
  4. return $Cate[' title '];
Copy Code

I want to call this function in the template, which I can write in the template.

      1. {$vo. CID| Cate=# # #}

Http://www.thinkphp.cn/topic/1553.html

Ways to use custom functions in thinkphp templates

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.