PHP Classes

File: htdocs/xoops_lib/vendor/smarty/smarty/docs/programmers/advanced-features/advanced-features-postfilters.md

Recommend this page to a friend!
  Packages of Michael Beck   Xoops 2.5   htdocs/xoops_lib/vendor/smarty/smarty/docs/programmers/advanced-features/advanced-features-postfilters.md   Download  
File: htdocs/xoops_lib/vendor/smarty/smarty/docs/programmers/advanced-features/advanced-features-postfilters.md
Role: Example script
Content type: text/markdown
Description: Example script
Class: Xoops 2.5
Modular content management publication system
Author: By
Last change:
Date: 2 months ago
Size: 1,265 bytes
 

Contents

Class file image Download

Postfilters {#advanced.features.postfilters}

Template postfilters are PHP functions that your templates are ran through after they are compiled. Postfilters can be either registered or loaded from the plugins directory by using the loadFilter() function or by setting the $autoload_filters variable. Smarty will pass the compiled template code as the first argument, and expect the function to return the result of the processing.

<?php
// put this in your application
function add_header_comment($tpl_source, Smarty_Internal_Template $template)
{
    return "<?php echo \"<!-- Created by Smarty! -->\n\"; ?>\n".$tpl_source;
}

// register the postfilter
$smarty->registerFilter('post','add_header_comment');
$smarty->display('index.tpl');
?>

  

The postfilter above will make the compiled Smarty template index.tpl look like:

<!-- Created by Smarty! -->
{rest of template content...}

  

See also registerFilter(), prefilters, outputfilters, and loadFilter().