-
[Lightemplate]
Copyright (c) 2009 Troy
Class name: Lightemplate
Run environment on php5.*
Project owners and author Troy
Code license: GNU General Public License v3
Email list:
Official site: http://www.tr0y.cn/
Created on:2009/5/1 Last update time:2009/5/6
lightemplate 是一个php模版类,调用方法简单,支持if else include之类的标签,
可以包含扩展函数,整个模版文件没有外部include和require,减少io操作,模版所调用的文件都整合到一个编译文件中.
加载三个模版变量,两个数组变量,比smarttemplate快平均2-3毫秒.
单纯加载模版文件,不设置任何变量lightemplate平均0.3毫秒左右,smarttemplate至少要1毫秒.
带有生产模式,测试模式,和调试模式.
调试模式可以打印加载的扩展,用到的模版变量,模版和编译文件,还有程序耗时等信息.
测试模式只是删除模版编译文件,生产模式不会删除模版编译文件,所以如果你在生产模式下更新过模版的话需要手动删除编译文件.
配置例子 :
$tempconf = array('templateDir'=>'./Tpl/',
'templateCompiledDir'=>'./Temp/Tpl_Compiled/',
'templateFileSuffix'=>'.tpl',
'templateExtDir'=>'./Common/smarttemplate_extensions/',
'templateSchema'=>'1');
如果你的php环境是5.3或以上版本,你可以这样实例化并使用里面的方法
$t = new Lightemplate($tempConf);$t->setFile('index');
$t->assign('test','hello world');
$t->output();
如果是5.3以下版本,那么应该这样
new Lightemplate($tempConf);Lightemplate::setFile('index');
Lightemplate::assign(array('test'=>array(array('id'=>'1','name'=>'username'),array('id'=>'2','name'=>'username2'))));
里面的test有两个数组,在模版里面应该这样:
{id} {name}
如果你要调用扩展函数,那么应该在模版应该这样写:
{your_function_name(params)}
当然还要在扩展目录中建立函数文件,文件名以函数名.php [function name.php] 命名.例如:
your_function_name.php 里面的代码应该是
function your_function_name($params){
/*somecode*/
}
如果你更新过模版,或者扩展函数,但又在生产模式下,编译文件将不会更新,你需要删除配置数组中templateCompiledDir键定义的目录下相应的编译文件.
你可以从code google的svn服务器获取最新的源代码: