thinkphp foreground HTML call function format output

Source: Internet
Author: User
Tags md5

Only output variables do not meet the needs of the template output, the built-in template engine support for template variables to use the regulator and formatting functions, in fact, is to provide function support, and support the use of multiple functions. The functions used for template labels can be PHP built-in functions or user-defined functions, unlike smarty, functions for templates do not require a special definition.

The function call format for the template variable is:

xml/html Code

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


{and $ symbol cannot have spaces, then the space of the argument is not a problem

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

Supports multiple functions that support spaces between functions

Supports function masking, which allows you to configure a list of prohibited functions in a configuration file

Support variable caching function, repeated variable string not multiple resolution

Use examples:

xml/html Code

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

The compiled PHP code is:

PHP code

<?php Echo (substr (Strtoupper (MD5 ($webTitle)), 0,3));

Note the relationship between the definition of a function and the order in which it is used, usually the first parameter of the function is the result of the previous variable or the previous function, and if your variable is not the first argument of the function, you need to use the anchor symbol, for example:

xml/html Code

{$create _time|date= "y-m-d", ###}

The compiled PHP is:

PHP code

<?php Echo (Date ("y-m-d", $create _time));?>

There is no limit to the use of functions, but you can allow the configuration tmpl_deny_func_list definition to disable the list of functions, and the Exit and ECHO functions are disabled by default to prevent damage to the template output, and we can add additional definitions, such as:

Tmpl_deny_func_list=> "Echo,exit,halt"

Use a half-width comma to separate multiple functions.

It also provides a quick way to call a function directly in a template file without having to pass a template variable, including two ways:

1. Execute method and output return value:

Format: {: function (...)}

For example, output the return value of the U method:

xml/html Code

{: U (' User/insert ')}

The compiled PHP code is

PHP code

<?php echo U (' User/insert ');? >

2, execution method but not output:

Format: {~function (...)}

For example, call the Say_hello function:

xml/html Code

{~say_hello (' thinkphp ')}

The compiled PHP code is:

PHP code

<?php say_hello (' thinkphp ');? >&NBSP;&NBSP

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: 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.