Custom functions
function. Yanga. php page is called with plug-in form
<?php/* * file name * function. Name of the function. php function.yanga.php * declared function name rule * smarty_function_ function name () smarty_function_yangA * parameter * 1. Arrays array * 2.smarty * templates using * <{yanga content= "I am mr.yang " color=" Red " size=" 7 " line=" 6 "}> * */ function smarty_function_yanga ($args, $smarty) { $str = '; for ($i =0; $i < $args [' line ']; $i + +) { $str .= "<font color= ' {$args [' Color ']} ' size= ' {$args [' Size ']} ' >{$args [' content ']}</font><br/> '; } return $str; }
Template tpl.php Page
<{yanga color= "Pink" content= "I am mr.yang AAAAA" line= "3" size= "7"}>
Browser output
I am Mr.yang
I am Mr.yang
I am Mr.yang
I am Mr.yang AAAAA
I am Mr.yang AAAAA
I am Mr.yang AAAAA
==========================================================
Custom block functions
Blocks function Block page
<?php/* * file name * block. function name .php block.worlda.php * declares the function name rule * smarty_block_ function name () smarty_block_worldA * parameter * 1. Attribute associative array * 2. * 3. The contents of the middle of the tag. parameter is smarty * 4. Reference parameter start true end false * Template using * <{worlda line= "3" color= "Blue" size= "7"}> * <{/worlda }> * */ function smarty_block_worlda ($ args, $content, $smarty,& $flag) { if (! $flag) { $str = "; for ($i =0; $i < $args [' line ']; $i + +) { $str .= " <font color= ' {$args[' Color '} ' size= ' {$args [' Size ']} ' >{$content}</font><br/> '; } return $str; } }
Template tpl.php Page
<{worlda line= "3" color= "Blue" size= "7"}>i AM block!<{/worlda}>
Browser output
I AM block!
I AM block!
I AM block!
==========================================================
This article is from the "Jin Sha Harbor" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1844004
PHP Smarty template Custom function functions and block functions blocks