WeiPHP插件模板中快速引入公共模板文件,weiphp創建於onethink之上,簡單修改代碼,無需填寫絕對路徑實現輕鬆引入模板。記錄一下,分享給須要的人。php
修改文件:html
ThinkPHP/Library/Think/Template.class.php佈局
3.2版本大約是326行左右。即parseInclude方法中this
修改後代碼貼出:插件
// 解析模板中的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; }
模板頁引入方式:code
使用addons代替路徑直接引入文件,這樣一來被引入的子模板一樣可使用其餘標籤變量。htm
<include file="addons:User\header.html" />