tp5.0、tp5.1、tp6.0视图输出字符串内容替换的写法
原创 2021-05-14 21:55:10
2 收藏 1 浏览957 评论0
琴朗
已发33篇
有侵犯版权请及时联系我们,我们将在24小时内删除文章。
投诉举报


很多时候,在视图文件中的路径都要使用变量。


(1)tp5.0中的写法

在config.php中写入下面的代码

return [
        'view_replace_str'   => [
		'__CSS__'      =>    '/static/home/css',
		'__JS__'      =>    '/static/home/js',
	    '__IMAGES__'    =>    '/static/home/images',
	       ],
]


(2)tp5.1和tp6.0的写法

tp5.1在template.php / tp6.0在view.php中写入下面的代码

return [

'tpl_cache'   => false,//关闭模板引擎缓存
'tpl_replace_string' => [
        '__CSS__'       =>    '/static/home/css',
        '__JS__'        =>    '/static/home/js',
        '__IMAGES__'    =>    '/static/home/images',
    ],
]


html中的写法

<link rel="stylesheet" href="__CSS__/bootstrap.min.css">

等同于

<link rel="stylesheet" href="/static/home/css/bootstrap.min.css">



评论(0) 我要评论