Smart.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2014 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. namespace Think\Template\Driver;
  12. /**
  13. * Smart模板引擎驱动
  14. */
  15. class Smart
  16. {
  17. /**
  18. * 渲染模板输出
  19. * @access public
  20. * @param string $templateFile 模板文件名
  21. * @param array $var 模板变量
  22. * @return void
  23. */
  24. public function fetch($templateFile, $var)
  25. {
  26. $templateFile = substr($templateFile, strlen(THEME_PATH));
  27. vendor('SmartTemplate.class#smarttemplate');
  28. $tpl = new \SmartTemplate($templateFile);
  29. $tpl->caching = C('TMPL_CACHE_ON');
  30. $tpl->template_dir = THEME_PATH;
  31. $tpl->compile_dir = CACHE_PATH;
  32. $tpl->cache_dir = TEMP_PATH;
  33. if (C('TMPL_ENGINE_CONFIG')) {
  34. $config = C('TMPL_ENGINE_CONFIG');
  35. foreach ($config as $key => $val) {
  36. $tpl->{$key} = $val;
  37. }
  38. }
  39. $tpl->assign($var);
  40. $tpl->output();
  41. }
  42. }