您的位置:首页 > 编程语言 > PHP开发

WeiPHP插件模板中快速引入公共模板文件

2016-01-25 11:40 513 查看
摘要: WeiPHP插件模板中快速引入公共模板文件,weiphp建立于onethink之上,简单修改代码,无需填写绝对路径实现轻松引入模板。

WeiPHP插件模板中快速引入公共模板文件,weiphp建立于onethink之上,简单修改代码,无需填写绝对路径实现轻松引入模板。记录一下,分享给需要的人。

修改文件:

ThinkPHP/Library/Think/Template.class.php

3.2版本大约是326行左右。即parseInclude方法中

修改后代码贴出:

// 解析模板中的include标签
protected function parseInclude($content, $extend = true) {

// 解析继承
if($extend)
$content    =   $this->parseExtend($content);
// 解析布局
$content    =   $this->parseLayout($content);
// 读取模板中的include标签
$find       =   preg_match_all('/'.$this->config['taglib_begin'].'include\s(.+?)\s*?\/'.$this->config['taglib_end'].'/is',$content,$matches);

if($find) {
for($i=0;$i<$find;$i++) {
$include    =   $matches[1][$i];
$array      =   $this->parseXmlAttrs($include);
$file       =   $array['file'];
unset($array['file']);
// 二次修改插件路径[start]
if(strstr($file,'addons:')){
$file = strtr($file,array('addons:'=>ONETHINK_ADDON_PATH._ADDONS.'/View/default/'));
$file = strtr($file,array('\\'=>'/'));
}
//二次修改插件路径[end]
$content    =   str_replace($matches[0][$i],$this->parseIncludeItem($file,$array,$extend),$content);
}
}
return $content;
}

模板页引入方式:

使用addons代替路径直接引入文件,这样一来被引入的子模板同样可以使用其他标签变量。

<include file="addons:User\header.html" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息