When using the PHP smarty template engine, you sometimes need to call some developer-defined functions, such as an encode function. This function is not embedded in smarty, so naturally, you need to first construct this function in PHP code, and then call this function in the template folder. The method is as follows:
For example, a function is designed in Foo. php.
/** <Br/> * the foo. php file generates a sub function, which is called through the smarty template. <Br/> */<br/> <? Php <br/> $ S = new smarty (); <br/> Function Sub ($ A, $ B) {<br/> return $ A + $ B; <br/>}< br/> $ S-> assign ("foo", "foo.html"); <br/>?>
The corresponding page can be displayed in the foo.html file after the authorization value is passed.
<! -- The above PHP file uses $ S-> display () to generate corresponding variables for the following HTML file: <br/> <HTML> <br/>... <br/> <{if $ browsertype = "ie"}> <br/> <TD align = "center"> <br/> <a target = "_ blank" href = "http://pharma.dxy.cn/info/productsearch.htm? Keyword = <{$ result [A]. drugname | keywordsencode: $ result [A]. drugname }>< br/> & field = 1 & Order = 0 & limit = 10 & infotype = 6 & category = & releasedate = 0 & agencyname = & Area = & code ="> <{$ result [A]. drugname }></A> <br/> </TD> <br/> <{else}> <br/> <TD align = "center"> <br/> <a target = "_ blank" href = "http://pharma.dxy.cn/info/productsearch.htm? Keyword = <{$ result [A]. drugname | substring: $ result [A]. drugname }>< br/> & field = 1 & Order = 0 & limit = 10 & infotype = 6 & category = & releasedate = 0 & agencyname = & Area = & code ="> <{$ result [A]. drugname }></A> <br/> </TD> <br/> <{/if}> <br/> </ptml>
The above code
<{$ Result [A]. drugname | keywordsencode: $ result [A]. drugname}> indicates:
Use | to call the keywordsencode method in the PHP file. Use: To represent the parameter of the Parameter Function.