> Smarty模板引擎中文在线手册 > Compiler Functions [编译函数]

register_compiler_function(), unregister_compiler_function().

Example 16-6. simple compiler function简单编译函数

<?PHP
/*
 * smarty plugin
 * -------------------------------------------------------------
 * File: compiler.tplheader.php
 * Type: compiler
 * Name: tplheader
 * Purpose: Output header containing the source file name and
 * the time it was compiled.
 * -------------------------------------------------------------
 */
function smarty_compiler_tplheader($tag_arg, &$smarty)
{
 return "\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';";
}
?>

This function can be called from the template as:
这个函数在模板中以如下方式调用:

{* this function gets executed at compile time only *}
{tplheader}

The resulting PHP code in the compiled template would be something like this:
在编译之后的模板中被嵌入的PHP代码内容如下:

<php
echo 'index.tpl compiled at 2002-02-20 20:02';
?>