Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Compiler-Funktionen

Compiler-Funktionen werden während der Kompilierung des Template aufgerufen. Das ist nützlich, um PHP-Code oder zeitkritische statische Inhalte in ein Template einzufügen. Sind eine Compiler-Funktion und eine eigene Funktion unter dem selben Namen registriert, wird die Compiler-Funktion ausgeführt.

mixed smarty_compiler_name( $tag_arg,  
  &$smarty);  
string $tag_arg;
object &$smarty;
 

Die Compiler-Funktion erhä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ück, der in das Template eingefügt werden soll.

Sehen Sie dazu: register_compiler_function(), unregister_compiler_function().

Example 16.6. Einfache Compiler-Funktionen


<?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, &$smarty)
{
    return "\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';";
}
?>

     

Diese Funktion kann aus dem Template wie folgt aufgerufen werden:

      
      {* diese Funktion wird nur zum Kompilier-Zeitpunkt ausgeführt *}
      {tplheader}

Der resultierende PHP-Code würde ungefähr so aussehen:


<?php
echo 'index.tpl compiled at 2002-02-20 20:02';
?>

       

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 7 plus 15? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
Cheap Hosting @HostsVault
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com