Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

前置过滤器

前置过滤器是在模板编译之前调用的PHP函数。 该过滤器经常用于删除一些模板中的无用注释、检查注释的来源等等。

前置过滤器可以通过注册过滤器来调用, 或者放置到插件目录中,用 loadFilter()函数或者 设置 $autoload_filters来调用。

Smarty把模板源代码作为第一个参数传递到函数中,并期待函数返回经过处理的源代码。

Example 17.11. 使用前置过滤器

这个例子将删除全部模板中的HTML注释。


<?php
// 在PHP程序中
function remove_dw_comments($tpl_source, Smarty_Internal_Template $template)
{
    return preg_replace("/<!--#.*-->/U",'',$tpl_source);
}

// 注册过滤器
$smarty->registerFilter('pre','remove_dw_comments');
$smarty->display('index.tpl');
?>

  

参见 registerFilter(), 后置过滤器loadFilter().

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors