Use the PHP function's method_php template in the smarty Template

Source: Internet
Author: User
In the smarty template, if you want to use the php function in the displayed information, if there is only one parameter function, for example, the trim that goes to the blank space, it will be written as sample1.

The code is as follows:


<{$ Colname | trim}>


How can I write a function with three parameters like iconv? If it is written:
Sample 2

The code is as follows:


<{$ Colname | iconv: 'utf-8': 'gbk'}>


An error message is displayed upon execution.
Therefore, we will find that, starting from the usage of the functions applied on the smarty template page, in smaple 1, $ Row-> colname in front of trim is actually the first parameter of trim, use | in the middle to concatenate;
If you want to use a function with three parameters like iconv, you must write it as follows:
Sample 3

The code is as follows:


<{'Utf-8' | iconv: 'gbk': $ colname}>


That is
The first parameter of the function | function: the second parameter: the third parameter. In sample 3, the colname value is converted from UTF-8 to gbk.

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.