Prefilters/Postfilters

PHP Smarty

Smarty - the compiling PHP template engine
Prev 来源:PHP中文社区 Chapter 16. Extending Smarty With Plugins
利用插件扩展smarty
Next

Prefilters/Postfilters预滤器/后滤器

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File: prefilter.pre01.php
 * Type: prefilter
 * Name: pre01
 * Purpose: Convert html tags to be lowercase.
 * -------------------------------------------------------------
 */
 function smarty_prefilter_pre01($source, &$smarty)
 {
 return preg_replace('!<(\w+)[^>]+>!e', 'strtolower("$1")', $source);
 }
?>
<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File: postfilter.post01.php
 * Type: postfilter
 * Name: post01
 * Purpose: Output code that lists all current template vars.
 * -------------------------------------------------------------
 */
 function smarty_postfilter_post01($compiled, &$smarty)
 {
 $compiled = "<pre>\n<?php print_r(\$this->get_template_vars()); ?>\n</pre>" . $compiled;
 return $compiled;
 }
?>

Prev 来源:PHP中文社区 Home Next
Compiler Functions[编译函数] Up [输出过滤器]Output Filters