Sophie

Sophie

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

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

<HTML
><HEAD
><TITLE
>Compiler Functions</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="Block Functions"
HREF="plugins.block.functions.html"><LINK
REL="NEXT"
TITLE="Prefilters/Postfilters"
HREF="plugins.prefilters.postfilters.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.block.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.prefilters.postfilters.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="plugins.compiler.functions"
></A
>Compiler Functions</H1
><P
>&#13;     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
HREF="language.custom.functions.html"
>custom function</A
> registered
      under the same name, the compiler function has precedence.
    </P
><DIV
CLASS="funcsynopsis"
><A
NAME="AEN7313"
></A
><P
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>mixed <B
CLASS="function"
>smarty_compiler_<TT
CLASS="replaceable"
><I
>name</I
></TT
></B
></CODE
> (string $tag_arg, object &#38;$smarty)</CODE
></P
><P
></P
></DIV
><P
>&#13;     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
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN7323"
></A
><P
><B
>Example 16-6. A simple compiler function</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;compiler.tplheader.php<br />&nbsp;*&nbsp;Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compiler<br />&nbsp;*&nbsp;Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tplheader<br />&nbsp;*&nbsp;Purpose:&nbsp;&nbsp;Output&nbsp;header&nbsp;containing&nbsp;the&nbsp;source&nbsp;file&nbsp;name&nbsp;and<br />&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;time&nbsp;it&nbsp;was&nbsp;compiled.<br />&nbsp;*&nbsp;-------------------------------------------------------------<br />&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">smarty_compiler_tplheader</span><span style="color: #007700">(</span><span style="color: #0000BB">$tag_arg</span><span style="color: #007700">,&nbsp;&amp;</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #DD0000">"\necho&nbsp;'"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">_current_file&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&nbsp;compiled&nbsp;at&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d&nbsp;H:M'</span><span style="color: #007700">).&nbsp;</span><span style="color: #DD0000">"';"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></TD
></TR
></TABLE
><P
>&#13;      This function can be called from the template as:
     </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>{* this function gets executed at compile time only *}
{tplheader}</PRE
></TD
></TR
></TABLE
><P
>&#13;      The resulting PHP code in the compiled template would be something like this:
     </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: #007700">echo&nbsp;</span><span style="color: #DD0000">'index.tpl&nbsp;compiled&nbsp;at&nbsp;2002-02-20&nbsp;20:02'</span><span style="color: #007700">;<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.compiler.function.html"
>&#13;     <TT
CLASS="varname"
>register_compiler_function()</TT
></A
>,
     <A
HREF="api.unregister.compiler.function.html"
>&#13;     <TT
CLASS="varname"
>unregister_compiler_function()</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.block.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.prefilters.postfilters.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Block 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"
>Prefilters/Postfilters</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>