Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > 3ca7e0e5486da714e98ac79af09ca745 > files > 128

php-smarty2-doc-2.6.28-2.mga4.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Prefilters/Postfilters</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Smarty Manual">
<link rel="up" href="plugins.html" title="Chapter 16. Extending Smarty With Plugins">
<link rel="prev" href="plugins.compiler.functions.html" title="Compiler Functions">
<link rel="next" href="plugins.outputfilters.html" title="Output Filters">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Prefilters/Postfilters</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="plugins.compiler.functions.html">Prev</a> </td>
<th width="60%" align="center">Chapter 16. Extending Smarty With Plugins</th>
<td width="20%" align="right"> <a accesskey="n" href="plugins.outputfilters.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Prefilters/Postfilters">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="plugins.prefilters.postfilters"></a>Prefilters/Postfilters</h2></div></div></div>
<p>
     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">
<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table">
<tr>
<td><code class="funcdef">string <b class="fsfunc">smarty_prefilter_name</b>(</code></td>
<td>
<var class="pdparam">$source</var>, </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<var class="pdparam">&amp;$smarty</var><code>)</code>;</td>
<td> </td>
</tr>
</table>
<div class="paramdef-list">
<code>string <var class="pdparam">$source</var></code>;<br><code>object <var class="pdparam">&amp;$smarty</var></code>;</div>
<div class="funcprototype-spacer"> </div>
</div>
<p>
     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">
<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table">
<tr>
<td><code class="funcdef">string <b class="fsfunc">smarty_postfilter_name</b>(</code></td>
<td>
<var class="pdparam">$compiled</var>, </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<var class="pdparam">&amp;$smarty</var><code>)</code>;</td>
<td> </td>
</tr>
</table>
<div class="paramdef-list">
<code>string <var class="pdparam">$compiled</var></code>;<br><code>object <var class="pdparam">&amp;$smarty</var></code>;</div>
<div class="funcprototype-spacer"> </div>
</div>
<p>
     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>
<div class="example">
<a name="id3126764"></a><p class="title"><b>Example 16.7. prefilter plugin</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     prefilter.pre01.php
 * Type:     prefilter
 * Name:     pre01
 * Purpose:  Convert html tags to be lowercase.
 * -------------------------------------------------------------
 */
 function smarty_prefilter_pre01($source, &amp;$smarty)
 {
     return preg_replace('!&lt;(\w+)[^&gt;]+&gt;!e', 'strtolower("$1")', $source);
 }
?&gt;

     </pre></div>
</div>
<br class="example-break"><p></p>
<div class="example">
<a name="id3126781"></a><p class="title"><b>Example 16.8. postfilter plugin</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     postfilter.post01.php
 * Type:     postfilter
 * Name:     post01
 * Purpose:  Output code that lists all current template vars.
 * -------------------------------------------------------------
 */
 function smarty_postfilter_post01($compiled, &amp;$smarty)
 {
     $compiled = "&lt;pre&gt;\n&lt;?php print_r(\$this-&gt;get_template_vars()); ?&gt;\n&lt;/pre&gt;" . $compiled;
     return $compiled;
 }
?&gt;

     </pre></div>
</div>
<br class="example-break"><p>
     See also
     <a class="link" href="api.register.prefilter.html" title="register_prefilter()">
     <code class="varname">register_prefilter()</code></a>,
     <a class="link" href="api.unregister.prefilter.html" title="unregister_prefilter()">
     <code class="varname">unregister_prefilter()</code></a>
        <a class="link" href="api.register.postfilter.html" title="register_postfilter()">
     <code class="varname">register_postfilter()</code></a>,
     <a class="link" href="api.unregister.postfilter.html" title="unregister_postfilter()">
     <code class="varname">unregister_postfilter()</code></a>.
    </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="plugins.compiler.functions.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="plugins.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="plugins.outputfilters.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Compiler Functions </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Output Filters</td>
</tr>
</table>
</div>
</body>
</html>