ThinkPHP2.1 增加PHPCMS模板引擎,支持PC标签(get,json)
本人经常使用PHPCMS模板引擎。
用ThinkPHP2.1 自带的,感觉不爽,花点时间增加了个PHPCMS模板引擎
BY 夜色紫宸风
功能:PHPCMS模板解析引擎,支持PC标签(get,json),也可以使用ThinkPHP2.1的模板数据,都支持
TemplatePhpcms.class.php
把这个文件放到 ThinkPHP\Lib\Think\Util\Template 文件夹中
<?php
/**
+------------------------------------------------------------------------------
* TemplateLite模板引擎解析类
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Util
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class TemplatePhpcms {
/**
+----------------------------------------------------------
* 渲染模板输出
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $templateFile 模板文件名
* @param array $var 模板变量
* @param string $charset 模板输出字符集
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
public function fetch($templateFile, $var, $charset) {
$templateFile = substr ( $templateFile, strlen ( TMPL_PATH ) );
$t=explode('/',$templateFile);
@extract($var);
include template($t[1],$t[2],$t[0]);
}
}
/**
* 模板调用
*
* @param $module
* @param $template
* @param $istag
* @return unknown_type
*/
function template($module = 'Index', $template = 'index', $style = 'default') {
$templateFile = $style.'/'.$module.'/'.$template;
vendor ( "TemplatePhpcms.class#phpcms" );
if (C ( 'TMPL_ENGINE_CONFIG' )) {
$config = C ( 'TMPL_ENGINE_CONFIG' );
} else {
$config = array ('template_dir' => TMPL_PATH, 'cache_dir' => CACHE_PATH, 'compile_dir' => TEMP_PATH );
}
$tpl = new Template_Phpcms ( $config );
$tpl->template_compile ( $templateFile );
return $config['cache_dir'].basename($template).'.php';
}
?>
class.phpcms.php
把这个文件放到 ThinkPHP\Vendor\TemplatePhpcms 文件夹中(TemplatePhpcms 这个目录要新建)
我倒。我汗。。贴上来,源码乱了。。。。
晕。压缩文件吧。。。
https://download.csdn.net/detail/wljk506/3798209
最后更新:2017-04-02 06:52:06