Smarty user-defined function usage example, smarty user-defined example. Smarty user-defined function usage example. smarty user-defined example this article describes the usage of smarty user-defined functions. For your reference, see phprequire_oncesmart smarty user-defined function usage example and smarty user-defined example.
This document describes the usage of smarty Udfs. We will share this with you for your reference. The details are as follows:
<? Phprequire_once "smarty. config. php"; // customize a function // call method: <{test1 times = "4" size = "5" con = "Hello, Liuyibao! "Color =" red "}> function test1 ($ args) {$ str =" "; for ($ I = 0; $ I <$ args ['Times ']; $ I ++) {$ str. ="{$ Args ['con ']}
";} Return $ str;} // customize a block function // call the function <{test1}> <{/test1}> function test2 ($ args, $ con) {$ str = ""; for ($ I = 0; $ I <$ args ['Times ']; $ I ++) {$ str. ="{$ Con}
";}Return $ str ;}// define a calculation method function jisuan ($ args) {switch ($ args ['operate']) {case" + ": $ res = $ args ['num1']-$ args ['num2']; break; case "-": $ res = $ args ['num1']-$ args ['$ num2']; break; case "*": $ res = $ args ['num1'] * $ args ['$ num2']; break; case "/": $ res = $ args ['num1']/$ args ['$ num2']; break;} return $ res ;} // register $ smarty-> register_function ("liuyibao", "test1"); // register the block function $ smarty-> register_block ("liuyibao2", "test2 "); // register function jis Uan $ smarty-> register_function ("jisuan", "jisuan"); // replace the variable $ smarty-> display ("function. tpl");?>
PS: We recommend several formatting, beautification, and conversion tools on this site to help you sort out messy code. I believe you can use them in future development:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/Formatting/encryption tools:
Http://tools.jb51.net/code/jscompress
Online XML formatting/compression tools:
Http://tools.jb51.net/code/xmlformat
JSON code formatting and beautification tools:
Http://tools.jb51.net/code/json
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Json code online Formatting/beautification/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat
SQL code online formatting and beautification tools:
Http://tools.jb51.net/code/sqlcodeformat