Smarty Basic syntax file references, and function usage

Source: Internet
Author: User

Smarty File References:

{include file= "HEAD.TPL"}

{include file= "HEAD.TPL" sitename= "blog Park"} Property sitename is passed to HEAD.TPL, you can call {$sitename} in the file

Use of functions in Smarty:

1. Use the PHP function directly:

Form: {variable | php built-in function: Parameter 2: Parameter 3}

Date ("y-m-d", $time)----> {"y-m-d" | Date: $time}

Str_replace (' d ', ' H ', $STR)---> {' d ' | str_replace: ' h ': $str}

2. Custom functions: Registering custom functions using the Registerplugin method

Form: {function name parameter 1 = parameter value parameter 2 = parameter value}

In the PHP file:

function test ($params) {

$p 1= $params [' P1 '];

$p 2= $params [' P2 '];

Return $p 1. $p 2;

}

$smarty->registerplugin (' function ', ' f_test ', ' test '}; Register the test function and use f_test in the template file

In the template file:

{f_test p1= ' abc ' p2= ' EDF '} This will pass an array of arrays to the function test (

[' p1 '] = ' abc ',

[' p2 '] = ' def '

)

Note

Smarty Basic syntax file references, and function usage

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.