aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/programmers/advanced-features/advanced-features-postfilters.md
blob: d3bad546aae3fb1275c697f35870b8731d6dd017 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Postfilters {#advanced.features.postfilters}
===========

Template postfilters are PHP functions that your templates are ran
through *after they are compiled*. Postfilters can be either
[registered](#api.register.filter) or loaded from the [plugins
directory](#variable.plugins.dir) by using the
[`loadFilter()`](#api.load.filter) function or by setting the
[`$autoload_filters`](#variable.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()`](#api.register.filter),
[prefilters](#advanced.features.prefilters),
[outputfilters](#advanced.features.outputfilters), and
[`loadFilter()`](#api.load.filter).