Get Smarty

Donate

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

Buy cheap glasses from Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Shop for 2018 World Cup Football Boots Online sale at guthjcc.com

Browse best 2018 world cup soccer cleats and shoes from SoccerAzteca.com

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.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 19 plus 13? (Are you human?)

Advertisement