PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Output Filters

Output filter plugins operate on a template's output, after the template is loaded and executed, but before the output is displayed.

string smarty_outputfilter_name( $template_output,  
  $template);  
string $template_output;
object $template;
 

The first parameter to the output filter function is the template output that needs to be processed, and the second parameter is the instance of Smarty invoking the plugin. The plugin is supposed to do the processing and return the results.

Example 262. An output filter plugin



<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     outputfilter.protect_email.php
 * Type:     outputfilter
 * Name:     protect_email
 * Purpose:  Converts @ sign in email addresses to %40 as
 *           a simple protection against spambots
 * -------------------------------------------------------------
 */
 
function smarty_outputfilter_protect_email($outputSmarty_Internal_Template $template)
 {
     return 
preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
                         
'$1%40$2'$output);
 }
?>

     

See also registerFilter(), unregisterFilter().

Smarty Template Engine