?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
void smarty_function_
name
(array $params, object &$smarty)
All attributes passed to template functions from the template are contained in the $params as an associative array. Either access those values directly, e.g. $params['start'] or use extract($params) to import them into the symbol table.
模板傳遞給模板函數(shù)的所有的屬性都包含在參數(shù)數(shù)組 $params 中,既可以通過如: $params['start'] 的方式直接處理其中的值,也可以使用 extract($params) 的方式將所有值導(dǎo)入符號表中。
The output (return value) of the function will be substituted in place of the function tag in the template (fetch() function, for example). Alternatively, the function can simply perform some other task without any output (assign() function).
函數(shù)輸出(返回值)的內(nèi)容將取代模板中函數(shù)名稱出現(xiàn)的位置(例如:fetch()函數(shù))。同時函數(shù)也可能只是執(zhí)行些后臺任務(wù),并無任何輸出
If the function needs to assign some variables to the template or use some other Smarty-provided functionality, it can use the supplied $smarty object to do so.
如果函數(shù)需要向模板中增加變量或者使用Smarty提供的某些功能,可以通過 $smarty 對象實現(xiàn)。
See also相關(guān)內(nèi)容: register_function(), unregister_function().
Example 16-1. function plugin with output例16-1:有輸出插件函數(shù)
|
which can be used in the template as:
在模板中調(diào)用方法如下:
Question: Will we ever have time travel? Answer: {eightball}. |
Example 16-2. function plugin without output例16-2:無輸出插件函數(shù)
|