Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 3ca7e0e5486da714e98ac79af09ca745 > files > 5

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</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Smarty Manual">
<link rel="up" href="advanced.features.html" title="Chapter 15. Advanced Features">
<link rel="prev" href="advanced.features.html" title="Chapter 15. Advanced Features">
<link rel="next" href="advanced.features.postfilters.html" title="Postfilters">
</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</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="advanced.features.html">Prev</a> </td>
<th width="60%" align="center">Chapter 15. Advanced Features</th>
<td width="20%" align="right"> <a accesskey="n" href="advanced.features.postfilters.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Prefilters">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="advanced.features.prefilters"></a>Prefilters</h2></div></div></div>
<p>
  Template prefilters are PHP functions that your templates are ran through
  <span class="emphasis"><em>before they are compiled</em></span>. This is good for preprocessing
  your templates to remove unwanted comments, keeping an eye on what people are
  putting in their templates, etc.
 </p>
<p>
  Prefilters can be either <a class="link" href="api.register.prefilter.html" title="register_prefilter()">registered</a> or loaded from
  the <a class="link" href="variable.plugins.dir.html" title="$plugins_dir">plugins directory</a>
  by using <a class="link" href="api.load.filter.html" title="load_filter()"><code class="varname">load_filter()</code></a> function or
  by setting the <a class="link" href="variable.autoload.filters.html" title="$autoload_filters">
  <em class="parameter"><code>$autoload_filters</code></em></a> variable.
 </p>
<p>
  Smarty will pass the template source code as the first argument, and
  expect the function to return the resulting template source code.
 </p>
<div class="example">
<a name="id3120942"></a><p class="title"><b>Example 15.2. Using a template prefilter</b></p>
<div class="example-contents">
<p>
     This will remove all the html comments in the template source.
  </p>
<pre class="programlisting">

&lt;?php
// put this in your application
function remove_dw_comments($tpl_source, &amp;$smarty)
{
    return preg_replace("/&lt;!--#.*--&gt;/U",'',$tpl_source);
}

// register the prefilter
$smarty-&gt;register_prefilter('remove_dw_comments');
$smarty-&gt;display('index.tpl');
?&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="advanced.features.postfilters.html" title="Postfilters">postfilters</a>
 and
 <a class="link" href="api.load.filter.html" title="load_filter()"><code class="varname">load_filter()</code></a>.
 </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="advanced.features.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="advanced.features.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="advanced.features.postfilters.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 15. Advanced Features </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Postfilters</td>
</tr>
</table>
</div>
</body>
</html>