Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > by-pkgid > 8377d4bb25a3992aad680df2952f4b71 > files > 130

php-smarty-doc-2.6.26-1mdv2010.0.noarch.rpm

<HTML
><HEAD
><TITLE
>Prefilters/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="Extending Smarty With Plugins"
HREF="plugins.html"><LINK
REL="PREVIOUS"
TITLE="Compiler Functions"
HREF="plugins.compiler.functions.html"><LINK
REL="NEXT"
TITLE="Output Filters"
HREF="plugins.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="plugins.compiler.functions.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 16. Extending Smarty With Plugins</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="plugins.outputfilters.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="plugins.prefilters.postfilters"
></A
>Prefilters/Postfilters</H1
><P
>&#13;     Prefilter and postfilter plugins are very similar in concept; where
     they differ is in the execution -- more precisely the time of their
     execution.
    </P
><DIV
CLASS="funcsynopsis"
><A
NAME="AEN7338"
></A
><P
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>string <B
CLASS="function"
>smarty_prefilter_<TT
CLASS="replaceable"
><I
>name</I
></TT
></B
></CODE
> (string $source, object &#38;$smarty)</CODE
></P
><P
></P
></DIV
><P
>&#13;     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.
    </P
><DIV
CLASS="funcsynopsis"
><A
NAME="AEN7348"
></A
><P
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>string <B
CLASS="function"
>smarty_postfilter_<TT
CLASS="replaceable"
><I
>name</I
></TT
></B
></CODE
> (string $compiled, object &#38;$smarty)</CODE
></P
><P
></P
></DIV
><P
>&#13;     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.
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN7358"
></A
><P
><B
>Example 16-7. prefilter plugin</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*<br />&nbsp;*&nbsp;Smarty&nbsp;plugin<br />&nbsp;*&nbsp;-------------------------------------------------------------<br />&nbsp;*&nbsp;File:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefilter.pre01.php<br />&nbsp;*&nbsp;Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefilter<br />&nbsp;*&nbsp;Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pre01<br />&nbsp;*&nbsp;Purpose:&nbsp;&nbsp;Convert&nbsp;html&nbsp;tags&nbsp;to&nbsp;be&nbsp;lowercase.<br />&nbsp;*&nbsp;-------------------------------------------------------------<br />&nbsp;*/<br />&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">smarty_prefilter_pre01</span><span style="color: #007700">(</span><span style="color: #0000BB">$source</span><span style="color: #007700">,&nbsp;&amp;</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">)<br />&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">preg_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'!&lt;(\w+)[^&gt;]+&gt;!e'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'strtolower("$1")'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$source</span><span style="color: #007700">);<br />&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
></P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN7362"
></A
><P
><B
>Example 16-8. postfilter plugin</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*<br />&nbsp;*&nbsp;Smarty&nbsp;plugin<br />&nbsp;*&nbsp;-------------------------------------------------------------<br />&nbsp;*&nbsp;File:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;postfilter.post01.php<br />&nbsp;*&nbsp;Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;postfilter<br />&nbsp;*&nbsp;Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;post01<br />&nbsp;*&nbsp;Purpose:&nbsp;&nbsp;Output&nbsp;code&nbsp;that&nbsp;lists&nbsp;all&nbsp;current&nbsp;template&nbsp;vars.<br />&nbsp;*&nbsp;-------------------------------------------------------------<br />&nbsp;*/<br />&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">smarty_postfilter_post01</span><span style="color: #007700">(</span><span style="color: #0000BB">$compiled</span><span style="color: #007700">,&nbsp;&amp;</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">)<br />&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$compiled&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"&lt;pre&gt;\n&lt;?php&nbsp;print_r(\$this-&gt;get_template_vars());&nbsp;?&gt;\n&lt;/pre&gt;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$compiled</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$compiled</span><span style="color: #007700">;<br />&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;     See also
     <A
HREF="api.register.prefilter.html"
>&#13;     <TT
CLASS="varname"
>register_prefilter()</TT
></A
>,
     <A
HREF="api.unregister.prefilter.html"
>&#13;     <TT
CLASS="varname"
>unregister_prefilter()</TT
></A
>
        <A
HREF="api.register.postfilter.html"
>&#13;     <TT
CLASS="varname"
>register_postfilter()</TT
></A
>,
     <A
HREF="api.unregister.postfilter.html"
>&#13;     <TT
CLASS="varname"
>unregister_postfilter()</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="plugins.compiler.functions.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="plugins.outputfilters.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Compiler Functions</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="plugins.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Output Filters</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>