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