插件窝 干货文章 thinkphp5模板include引入动态模板方法(路径使用变量)

thinkphp5模板include引入动态模板方法(路径使用变量)

php thinkphp include thinkphp5 模板 735    来源:插件窝    2021-07-08

使用thinkphp5在模板页面想动态引入不同的模板,但是不能被正常解析,看了网上的几种方法,只能去修改原始方法文件了,具体如下:


{include file=”$param/head”}

<include file="$template1" />


修改文件


thinkphp\library\think\Template.php文件下的parseInclude方法

image.png

添加的代码如下:

if(isset($array['append']) &&  $array['append']){
    if(0===strpos($array['append'],'$')){
        $array['append'] = $this->get(substr($array['append'],1));
    }
    $file = $array['append'].$array['file'];
    unset($array['append']);
}else{
    $file  = $array['file'];
}