template_url()与url_asset()资源URL📅 2025-09-05  |  👁 404 次浏览

template_url($file='')返回当前模板静态资源URL,自动兼容市场源目录。url_asset($path)返回SITE_URL+/路径。

使用方式

echo template_url('static/style.css');
// 输出: http://localhost:8080/templates/mytpl/static/style.css

echo url_asset('static/upload/image/123.jpg');
// 输出: http://localhost:8080/static/upload/image/123.jpg

echo url_asset('https://cdn.example.com/lib.js');
// 传完整http(s)地址原样返回
  • template_url()自动兼容市场源目录
  • url_asset()用于全站公共资源
  • url_asset()传完整http(s)地址原样返回
  • 带版本号避免缓存: template_url('static/style.css').'?v='.$rnd

芒阳网络团域cms开发中心

Copyright © 2023 刀客CMS内容管理系统