<HTML ><HEAD ><TITLE >Postfilters</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Smarty Manual" HREF="index.html"><LINK REL="UP" TITLE="Advanced Features" HREF="advanced.features.html"><LINK REL="PREVIOUS" TITLE="Prefilters" HREF="advanced.features.prefilters.html"><LINK REL="NEXT" TITLE="Output Filters" HREF="advanced.features.outputfilters.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Smarty Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="advanced.features.prefilters.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 15. Advanced Features</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="advanced.features.outputfilters.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="advanced.features.postfilters" ></A >Postfilters</H1 ><P > Template postfilters are PHP functions that your templates are ran through <SPAN CLASS="emphasis" ><I CLASS="emphasis" >after they are compiled</I ></SPAN >. Postfilters can be either <A HREF="api.register.postfilter.html" >registered</A > or loaded from the <A HREF="variable.plugins.dir.html" >plugins directory</A > by using the <A HREF="api.load.filter.html" ><TT CLASS="varname" >load_filter()</TT ></A > function or by setting the <A HREF="variable.autoload.filters.html" > <TT CLASS="parameter" ><I >$autoload_filters</I ></TT ></A > variable. Smarty will pass the compiled template code as the first argument, and expect the function to return the result of the processing. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6947" ></A ><P ><B >Example 15-3. Using a template postfilter</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// put this in your application<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">add_header_comment</span><span style="color: #007700">(</span><span style="color: #0000BB">$tpl_source</span><span style="color: #007700">, &</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">)<br />{<br /> return </span><span style="color: #DD0000">"<?php echo \"<!-- Created by Smarty! -->\n\"; ?>\n"</span><span style="color: #007700">.</span><span style="color: #0000BB">$tpl_source</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// register the postfilter<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">register_postfilter</span><span style="color: #007700">(</span><span style="color: #DD0000">'add_header_comment'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">display</span><span style="color: #007700">(</span><span style="color: #DD0000">'index.tpl'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ><P > The postfilter above will make the compiled Smarty template <TT CLASS="filename" >index.tpl</TT > look like: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" ><!-- Created by Smarty! --> {* rest of template content... *}</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="api.register.postfilter.html" ><TT CLASS="varname" >register_postfilter()</TT ></A >, <A HREF="advanced.features.prefilters.html" >prefilters</A > and <A HREF="api.load.filter.html" ><TT CLASS="varname" >load_filter()</TT ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="advanced.features.prefilters.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="advanced.features.outputfilters.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Prefilters</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="advanced.features.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Output Filters</TD ></TR ></TABLE ></DIV ></BODY ></HTML >