Just the output variable does not meet the needs of the template output, the built-in template engine supports the use of the template variable regulator and formatting functions, in fact, provide function support, and support the use of multiple functions simultaneously. Functions used for template labels can be PHP built-in functions or user-defined functions, unlike smarty, which do not require special definitions for the functions used in templates.
The function call format for template variables is:
xml/html Code
-
- {$varname |function1| function2 = arg1 ,ARG2,###  }
Description
There can be no spaces between {and $ symbols, there is no problem with the space behind the argument
# # #表示模板变量本身的参数位置
Support for multiple functions, space between functions
Supports function masking, which allows you to configure a list of prohibited functions in a configuration file
Support variable cache function, repeat variable string not multiple parsing
Examples of Use:
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 that the definition of the function and the corresponding relationship of the order of use, usually the first parameter of the function is the previous variable or the result of the previous function, if your variable is not the first parameter of the function, you need to use a positional 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 configuration tmpl_deny_func_list to define a list of disabled 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"
Multiple functions are separated by commas.
It also provides a quick way to call a function directly in a template file, without having to pass through a template variable, including two different ways:
1. Execute the method and output the return value:
Format: {: function (...)}
For example, the return value of the output U method:
xml/html Code
- {: U (' User/insert ')}
The compiled PHP code is
PHP code
- <?php Echo U (' User/insert ');? >
2, the execution method but does 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 ');? >
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
thinkphp Foreground HTML call function formatted output