编译函数仅会在模æ�¿çš„编译过程ä¸è°ƒç”¨ï¼Œ 它对模æ�¿åµŒå…¥PHP代ç �或者对时间æ•�感的内容时比较有用。 如果å�Œæ—¶å˜åœ¨ç¼–译函数和 自定义函数,那么编译函数会优先使用。
mixed smarty_compiler_name( |
$params, | Â |
| Â |
$smarty); |
 |
array $params;object $smarty;编译函数有两个å�‚数:已预编译的å�˜é‡�å—符串数组,å�ŠSmarty对象。 该函数将会返回嵌入到模æ�¿çš„PHP代ç �。
Example 18.6. 一个简�的编译函数
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: compiler.tplheader.php
* Type: compiler
* Name: tplheader
* Purpose: 输出模�文件�和编译时间
* -------------------------------------------------------------
*/
function smarty_compiler_tplheader($params, Smarty $smarty)
{
return "<?php\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';\n?>";
}
?>
模�内调用:
{* æ¤å‡½æ•°ä»…在编译时执行 *}
{tplheader}
在编译å�Žçš„æ–‡ä»¶ä¸ï¼ŒPHP代ç �如下:
<?php
echo 'index.tpl compiled at 2002-02-20 20:02';
?>
��:
registerPlugin(),
unregisterPlugin().
