Files
smarty/docs/de/programmers/plugins/plugins-compiler-functions.xml
2004-04-13 11:47:32 +00:00

86 lines
2.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="plugins.compiler.functions"><title>Compiler-Funktionen</title>
<para>
Compiler-Funktionen werden w&auml;hrend der Kompilierung des Template
aufgerufen. Das ist n&uuml;tzlich, um PHP-Code oder zeitkritische statische
Inhalte in ein Template einzuf&uuml;gen. Sind eine Compiler-Funktion und
eine eigene Funktion unter dem selben Namen registriert, wird die
Compiler-Funktion ausgef&uuml;hrt.
</para>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>smarty_compiler_<replaceable>name</replaceable></function></funcdef>
<paramdef>string <parameter>$tag_arg</parameter></paramdef>
<paramdef>object <parameter>&amp;$smarty</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Die Compiler-Funktion erh&auml;lt zwei Parameter: die Tag-Argument Zeichenkette
- also alles ab dem Funktionsnamen bis zum schliessenden Trennzeichen - und
das Smarty Objekt. Gibt den PHP-Code zur&uuml;ck, der in das Template eingef&uuml;gt werden
soll.
</para>
<para>
Sehen Sie dazu:
<link linkend="api.register.compiler.function">register_compiler_function()</link>,
<link linkend="api.unregister.compiler.function">unregister_compiler_function()</link>.
</para>
<example>
<title>Einfache Compiler-Funktionen</title>
<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;</programlisting>
<para>
Diese Funktion kann aus dem Template wie folgt aufgerufen werden:
</para>
<programlisting>
{* diese Funktion wird nur zum Kompilier-Zeitpunkt ausgef&uuml;hrt *}
{tplheader}</programlisting>
<para>
Der resultierende PHP-Code w&uuml;rde ungef&auml;hr so aussehen:
</para>
<programlisting>
&lt;php
echo 'index.tpl compiled at 2002-02-20 20:02';
?&gt;</programlisting>
</example>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->