[原创] Lightemplate - php模版类

  • [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:

      ooofox@msn.com

      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服务器获取最新的源代码:

     

      http://lightemplate0.googlecode.com

      http://lightemplate0.googlecode.com/svn/trunk/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值