Smarty Base Plug-in

Source: Internet
Author: User

1. Follow the original system main program, data, function library, interface, etc., change it does not affect the whole. is essentially a function.

2. Plug-in common type: functions function Plug-in

modifiers modifier plug-in (variable adjuster plugin)

Block functions block Function plugin

3. Create and use plugins:

(1) Use the Registerplugin method to register the written plugin.

(2) Put the plug-in into the plugins directory in the Lib directory of the Smarty extract directory

(3) PHP built-in functions, can be directly used in the template as a variable adjuster.

Definition and use of three common plug-ins

Functions function Plugin:

Define the file in Lib/plugins function.test.php

function Smarty_function_test ($params) {//smarty_function_ plug-in name

$width = $params [' width ']; $params receive Array (parameter 1=> parameter value, parameter 2=> parameter value);

$height = $params [' height '];

$area = $width * $height;

return $area;

}

Called in the template file:

{Test width=200 height=100}

modifier plug-in (variable adjuster plug-in):

Define the file in Lib/plugins modifier.test.php

function Smarty_modifier_test ($utime, $format) {//smarty_modifer_ plug-in name

Return Date ($format, $utime);

}

PHP File: $smarty->assign (' Time ', Time ());

Called in the template file:

{Time | test: "Y-m-d h:i:s"}

Block Plugin (block functions plugin):

Define the file in Lib/plugins block.test.php

function Smarty_block_test ($params, $content) {//smarty_block_ plug-in name

$replace = $params [' Replace '];

$maxnum = $params [' maxnum];

if ($replace = = ' true ') {

$content = Str_replace (', ', ', ', $content);

$content = Str_replace ('. ', '. ', $content);

}

$content = Sub_str ($content, ' 0 ', $maxnum);

return $content;

}

PHP File: $smarty->assign (' str ', "hello,my name is Lilei. How is it? ");

Called in the template file:

{Test replace= ' true ' maxnum=20}

{$STR}

{/test}

Smarty Base Plug-in

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.