TemplateSmart.class.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. defined('THINK_PATH') or exit();
  12. /**
  13. * Smart模板引擎驱动
  14. * @category Extend
  15. * @package Extend
  16. * @subpackage Driver.Template
  17. * @author liu21st <liu21st@gmail.com>
  18. */
  19. class TemplateSmart {
  20. /**
  21. * 渲染模板输出
  22. * @access public
  23. * @param string $templateFile 模板文件名
  24. * @param array $var 模板变量
  25. * @return void
  26. */
  27. public function fetch($templateFile,$var) {
  28. $templateFile = substr($templateFile,strlen(THEME_PATH));
  29. vendor('SmartTemplate.class#smarttemplate');
  30. $tpl = new SmartTemplate($templateFile);
  31. $tpl->caching = C('TMPL_CACHE_ON');
  32. $tpl->template_dir = THEME_PATH;
  33. $tpl->compile_dir = CACHE_PATH ;
  34. $tpl->cache_dir = TEMP_PATH ;
  35. if(C('TMPL_ENGINE_CONFIG')) {
  36. $config = C('TMPL_ENGINE_CONFIG');
  37. foreach ($config as $key=>$val){
  38. $tpl->{$key} = $val;
  39. }
  40. }
  41. $tpl->assign($var);
  42. $tpl->output();
  43. }
  44. }