Sophie

Sophie

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

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

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Compiler Functions</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.block.functions.html" title="Block Functions">
<link rel="next" href="plugins.prefilters.postfilters.html" title="Prefilters/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">Compiler Functions</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="plugins.block.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.prefilters.postfilters.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Compiler Functions">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="plugins.compiler.functions"></a>Compiler Functions</h2></div></div></div>
<p>
     Compiler functions are called only during compilation of the template.
     They are useful for injecting PHP code or time-sensitive static
     content into the template. If there is both a compiler function and a
     <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">custom function</a> registered
      under the same name, the compiler function has precedence.
    </p>
<div class="funcsynopsis">
<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table">
<tr>
<td><code class="funcdef">mixed <b class="fsfunc">smarty_compiler_name</b>(</code></td>
<td>
<var class="pdparam">$tag_arg</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">$tag_arg</var></code>;<br><code>object <var class="pdparam">&amp;$smarty</var></code>;</div>
<div class="funcprototype-spacer"> </div>
</div>
<p>
     The compiler function is passed two parameters: the tag argument
     string - basically, everything from the function name until the ending
     delimiter, and the Smarty object. It's supposed to return the PHP code
     to be injected into the compiled template.
    </p>
<div class="example">
<a name="id3126166"></a><p class="title"><b>Example 16.6. A simple compiler function</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     compiler.tplheader.php
 * Type:     compiler
 * Name:     tplheader
 * Purpose:  Output header containing the source file name and
 *           the time it was compiled.
 * -------------------------------------------------------------
 */
function smarty_compiler_tplheader($tag_arg, &amp;$smarty)
{
    return "\necho '" . $smarty-&gt;_current_file . " compiled at " . date('Y-m-d H:M'). "';";
}
?&gt;

</pre>
<p>
      This function can be called from the template as:
     </p>
<pre class="programlisting">

{* this function gets executed at compile time only *}
{tplheader}

     </pre>
<p>
      The resulting PHP code in the compiled template would be something like this:
     </p>
<pre class="programlisting">

&lt;?php
echo 'index.tpl compiled at 2002-02-20 20:02';
?&gt;

     </pre>
</div>
</div>
<br class="example-break"><p>
     See also
     <a class="link" href="api.register.compiler.function.html" title="register_compiler_function()">
     <code class="varname">register_compiler_function()</code></a>,
     <a class="link" href="api.unregister.compiler.function.html" title="unregister_compiler_function()">
     <code class="varname">unregister_compiler_function()</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.block.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.prefilters.postfilters.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Block Functions </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Prefilters/Postfilters</td>
</tr>
</table>
</div>
</body>
</html>