本文共 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/