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

Funzioni di Compilazione

Le funzioni di compilazione sono chiamate solo durante la compilazione del template. Sono utili per inserire nel template codice PHP o contenuto statico dipendente dal momento (ad es. l'ora). Se esistono una funzione di compilazione e una funzione personalizzata registrate sotto lo stesso nome, la funzione di compilazione ha la precedenza.

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

Alla funzione di compilazione vengono passati due parametri: la stringa che rappresenta l'argomento tag - fondamentalmente, tutto dal nome della funzione fino al delimitatore finale, e l'oggetto Smarty. Ci si aspetta che la funzione restituisca il codice PHP da inserire nel template compilato.

See also register_compiler_function(), unregister_compiler_function().

Example 16.6. semplice funzione di compilazione


<?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'). "';";
}
?>

Questa funzione può essere chiamata dal template in questo modo:

{* questa funzione viene eseguita solo al momento della compilazione *}
{tplheader}
     

Il codice PHP risultante nel template compilato sarà qualcosa di questo tipo:


<?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 8 plus 17? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
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
ASP.NET hosting @aspnethosting.co.uk