PHP Smarty template Custom function functions and block functions blocks

Source: Internet
Author: User
Tags smarty template

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

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.