博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
phpcms 2008 sp4的模板原理,tag的解析原理
阅读量:7056 次
发布时间:2019-06-28

本文共 1231 字,大约阅读时间需要 4 分钟。

phpcms中模板解析主要是通过global.func.php,的

function template($module = 'phpcms', $template = 'index', $istag = 0){	$compiledtplfile = TPL_CACHEPATH.$module.'_'.$template.'.tpl.php';  //  echo "$compiledtplfile";	if(TPL_REFRESH && (!file_exists($compiledtplfile)            || @filemtime(TPL_ROOT.TPL_NAME.'/'.$module.'/'.$template.'.html') > @filemtime($compiledtplfile) ||                    @filemtime(TPL_ROOT.TPL_NAME.'/tag.inc.php') > @filemtime($compiledtplfile)))	{		require_once PHPCMS_ROOT.'include/template.func.php';		template_compile($module, $template, $istag);	}	return $compiledtplfile;}
函数来实现的,这其中比较重要的是template_compile函数来实现的对模板的编译,编译过过程中使用了preg_replace这个函数并加了个/e参数,对tag,get这样的标签进行了替换

$str = preg_replace("/\{tag_([^}]+)\}/e", "get_tag('\\1')", $str);	$str = preg_replace("/\{get\s+([^}]+)\}/e", "get_parse('\\1')", $str);
举个例子,对于<div id="slide">{tag_首页幻灯片}</div>这个标签的解析的结果为, 

'url', 'target' => '_blank', 'width' => '296', 'height' => '164',));?>
function get_tag($tagname){	global $TAG;    if(!isset($TAG)) $TAG = cache_read('tag.inc.php', TPL_ROOT.TPL_NAME.'/');	return isset($TAG[$tagname]) ? '
' : '{tag_'.$tagname.'}';}
模板解析后,使用了inlude并解析后的文件包含进来,解析的内容默认是从template/default/tag.inc.php中取出的内容

转载地址:http://ljwll.baihongyu.com/

你可能感兴趣的文章
C#~异步编程再续~async异步方法与同步方法的并行
查看>>
图解NodeJS【基于事件、回调的单线程高性能服务器】原理
查看>>
基于MVC4+EasyUI的Web开发框架经验总结(4)--使用图表控件Highcharts
查看>>
liux之sed用法
查看>>
如何给caffe添加新的layer ?
查看>>
Windows下的字体美化
查看>>
13.9. Health Status
查看>>
Unable to execute dex: Multiple dex files define Lcom/kenai/jbosh/AbstractAttr
查看>>
微信小程序明星开发者博卡君专访
查看>>
什么是 Help Desk?
查看>>
【MySQL】Tokudb安装测试初探
查看>>
12C打补丁的简单尝试
查看>>
快速搭建主从的脚本和问题排查
查看>>
分割excel sheet
查看>>
SAP笔记-物料移动类型和后勤自动科目设置
查看>>
MySQL8.0新特性: 新的事务锁调度VATS简介
查看>>
后台(24)——Filter(1)
查看>>
[20160902]简单探究linux的free命令.txt
查看>>
Linux下PS命令详解 (转)
查看>>
使用@ResponseBody 出现错误Could not find acceptable representation
查看>>