php页面引用公共文件,WeiPHP插件模板中快速引入公共模板文件
发布日期:2021-06-24 11:22:09 浏览次数:3 分类:技术文章

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

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

$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代替路径直接引入文件,这样一来被引入的子模板同样可以使用其他标签变量。

转载地址:https://blog.csdn.net/weixin_32467749/article/details/116124065 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:php tracy,admin.php
下一篇:mysql中用户线程作用,mysql用户线程的建立与用户线程的状态源码解析

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月31日 07时34分31秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

spring boot 与 Ant Design of Vue 实现角色管理布局以及角色的列表(十九) 2019-04-27
spring boot 与 Ant Design of Vue 实现新增角色(二十) 2019-04-27
spring boot 与 Ant Design of Vue 实现修改角色(二十一) 2019-04-27
spring boot 与 Ant Design of Vue 实现删除角色(补二十一) 2019-04-27
spring boot 与 Ant Design of Vue 实现组织管理布局的实现(二十二) 2019-04-27
spring boot 与 Ant Design of Vue 实现左侧组织树(二十三) 2019-04-27
spring boot 与 Ant Design of Vue 实现新增组织(二十四) 2019-04-27
spring boot 与 Ant Design of Vue 实现修改组织(二十五) 2019-04-27
spring boot 与 Ant Design of Vue 实现删除组织(二十六) 2019-04-27
spring boot 与 Ant Design of Vue 实现获取用户列表(二十七) 2019-04-27
Druid连接池实现自定义场景的多数据库的连接 2019-04-27
PL/SQL数据库管理工具的使用 2019-04-27
带你玩转属于自己自己的spring-boot-starter系列(二) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之关联查询解决方案(三) 2019-04-27
什么是服务熔断? 2019-04-27
服务器压力过大?CPU打满?我来帮你快速检查Linux服务器性能 2019-04-27
C++面经总结之《Effective C++》(一) 2019-04-27
C++面经总结之《Effective C++》(二) 2019-04-27
这是什么“虎狼之词”啊!!!程序员的健康问题,看一线老中医怎么说!!! 2019-04-27
打开我的收藏夹 -- Python数据分析杂谈 2019-04-27