Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

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:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

编译函数

编译函数仅会在模�的编译过程中调用, 它对模�嵌入PHP代�或者对时间�感的内容时比较有用。 如果�时存在编译函数和 自定义函数,那么编译函数会优先使用。

mixed smarty_compiler_name( $params,  
  $smarty);  
array $params;
object $smarty;
 

编译函数有两个�数:已预编译的��字符串数组,�Smarty对象。 该函数将会返回嵌入到模�的PHP代�。

Example 18.6. 一个简�的编译函数


<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     compiler.tplheader.php
 * Type:     compiler
 * Name:     tplheader
 * Purpose:  输出模�文件�和编译时间
 * -------------------------------------------------------------
 */
function smarty_compiler_tplheader($params, Smarty $smarty)
{
    return "<?php\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';\n?>";
}
?>

模�内调用:


{* 此函数仅在编译时执行 *}
{tplheader}

     

在编译�的文件中,PHP代�如下:


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

     

��: registerPlugin(), unregisterPlugin().

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

Advertisement