�置过滤器和�置过滤器在概念上�常相似,��点仅在于执行的时机。
string smarty_prefilter_name( |
$source, | Â |
| Â |
$template); |
 |
string $source;object $template;å‰�置过滤器是在模æ�¿æº�ç �被编译å‰�的时刻执行。 第一个å�‚数是模æ�¿æº�ç �,æº�ç �å�¯èƒ½å·²è¢«å…¶ä»–过滤器处ç�†è¿‡çš„。 å‰�置过滤器æ�’件将处ç�†å¹¶è¿”回过滤å�Žçš„æº�ç �。 注æ„�这些返回的æº�ç �ä¸�会被ä¿�å˜ï¼Œå®ƒä»¬ä»…æ��供给编译使用。
string smarty_postfilter_name( |
$compiled, | Â |
| Â |
$template); |
 |
string $compiled;object $template;å�Žç½®è¿‡æ»¤å™¨ä¼šåœ¨ç¼–译器已ç»�把模æ�¿ç¼–译完æˆ�,但未ä¿�å˜åˆ°æ–‡ä»¶ç³»ç»Ÿçš„æ—¶å€™æ‰§è¡Œã€‚ 第一个å�‚数是已编译的代ç �,代ç �å�¯èƒ½è¢«å…¶ä»–过滤器处ç�†è¿‡çš„。 å�Žç½®è¿‡æ»¤å™¨å°†è¿›è¡Œå¤„ç�†å¹¶è¿”回处ç�†å�Žçš„代ç �。
Example 18.7. �置过滤器
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: prefilter.pre01.php
* Type: prefilter
* Name: pre01
* Purpose: 转æ�¢HTMLæ ‡ç¾ä¸ºå°�写
* -------------------------------------------------------------
*/
function smarty_prefilter_pre01($source, Smarty_Internal_Template $template)
{
return preg_replace('!<(\w+)[^>]+>!e', 'strtolower("$1")', $source);
}
?>
Example 18.8. �置过滤器
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: postfilter.post01.php
* Type: postfilter
* Name: post01
* Purpose: 列出当�模�的��
* -------------------------------------------------------------
*/
function smarty_postfilter_post01($compiled, Smarty_Internal_Template $template)
{
$compiled = "<pre>\n<?php print_r(\$template->getTemplateVars()); ?>\n</pre>" . $compiled;
return $compiled;
}
?>
��:
registerFilter() 和
unregisterFilter().
