thinkphp Foreground HTML call function formatted output

Source: Internet
Author: User

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

    1. {$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

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


The compiled PHP code is:



PHP code

  1. <?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

    1. {$create _time| Date = "Y-m-d" ,###}  


The compiled PHP is:



PHP code

  1. <?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

    1. {: U (' User/insert ')}


The compiled PHP code is



PHP code

    1. <?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

    1. {~say_hello (' thinkphp ')}


The compiled PHP code is:



PHP code

    1. <?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

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.