Get Smarty


Donate Bitcoin Bitcoin

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

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from and save up to 80%.

Buy prescription glasses from and save.

Cheap Glasses Now On Sale at Starts At $7.95.

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

Find Wedding Dresses Online at Canada from

Find your local domestic cleaner

Brautkleider auf

Find free files to download on

Looking For Affordable Wedding Dresses 2015 at Best Prices On

Shop high quality cheap prom dresses on

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store



Prefilter and postfilter plugins are very similar in concept; where they differ is in the execution -- more precisely the time of their execution.

string smarty_prefilter_name( $source,  
string $source;
object $template;

Prefilters are used to process the source of the template immediately before compilation. The first parameter to the prefilter function is the template source, possibly modified by some other prefilters. The plugin is supposed to return the modified source. Note that this source is not saved anywhere, it is only used for compilation.

string smarty_postfilter_name( $compiled,  
string $compiled;
object $template;

Postfilters are used to process the compiled output of the template (the PHP code) immediately after the compilation is done but before the compiled template is saved to the filesystem. The first parameter to the postfilter function is the compiled template code, possibly modified by other postfilters. The plugin is supposed to return the modified version of this code.

Example 18.7. prefilter plugin

 * Smarty plugin
 * -------------------------------------------------------------
 * File:     prefilter.pre01.php
 * Type:     prefilter
 * Name:     pre01
 * Purpose:  Convert html tags to be lowercase.
 * -------------------------------------------------------------
 function smarty_prefilter_pre01($source, Smarty_Internal_Template $template)
     return preg_replace('!<(\w+)[^>]+>!e', 'strtolower("$1")', $source);


Example 18.8. postfilter plugin

 * 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_Internal_Template $template)
     $compiled = "<pre>\n<?php print_r(\$template->getTemplateVars()); ?>\n</pre>" . $compiled;
     return $compiled;


See also registerFilter() and unregisterFilter().

No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 4 plus 13? (Are you human?)


Sponsors [info]

UK Web Hosting
Best Web Hosting
Web Hosting UK
Unlimited Web Hosting
App Entwicklung
First Click Internet Marketing
Credit Card Processing Company
Cleaning Services Chicago