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" />
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有