> Smarty模板引擎中文在线手册 > Postfilters [后过滤器]

registered or loaded from the plugins directory by using load_filter() function or by setting $autoload_filters variable. smarty will pass the compiled template code as the first argument, and expect the function to return the result of the processing.

模板后过滤器是一些PHP函数,模板就是在那些函数编译后才运行。后过滤器同样能够通过 load filter() 函数和设置 $autoload filters 变量来注册或者从工具目录里载入。SMARTY将传递模板输出作为第一个参数,通过自定义函数返回处理结果。

 

Example 15-3. using a template postfilter

<?php
// put this in your application
function add_header_comment($tpl_source, &$smarty)
{
 return "<?php echo \"<!-- Created by Smarty! -->\n\" ?>\n".$tpl_source;
}

// register the postfilter
$smarty->register_postfilter("add_header_comment");
$smarty->display("index.tpl");
?>

{* compiled Smarty template index.tpl *}
<!-- Created by Smarty! -->
{* rest of template content... *}

上一篇:
下一篇: