php Smarty模版引擎中引入javascript源文件

采用XAPM开发Php的网站,使用了Smarty模版引擎。

源码如下:


define('WEB_INCLUDE',str_replace("\\", '/', dirname(__FILE__)));
define('WEB_PHP', dirname(WEB_INCLUDE));
define('WEB_CLASS',WEB_PHP . '/class');
define('WEB_DIR', dirname(WEB_PHP));
define('WEB_Tpl_Engine', WEB_PHP . '/smarty');
define('WEB_Tpl_Path', WEB_DIR . '/templets');
define('WEB_Tpl_Cache_Time', 0);


public static function get_tpl()
    {
        if(null === self::$smart_tpl){
            require_once(WEB_Tpl_Engine . '/Smarty.class.php');
            self::$smart_tpl = new Smarty();
            self::$smart_tpl->template_dir = WEB_Tpl_Path;
            self::$smart_tpl->compile_dir = WEB_Tpl_Engine . '/template_c';
            self::$smart_tpl->config_dir = WEB_Tpl_Engine . '/configs';
            self::$smart_tpl->cache_dir = WEB_Tpl_Engine . '/cache';
            if(WEB_Tpl_Cache_Time > 0){
                self::$smart_tpl->caching = true;
                self::$smart_tpl->cache_lifetime = WEB_Tpl_Cache_Time;
            }else{
                self::$smart_tpl->caching = false;
                self::$smart_tpl->cache_lifetime = 0;
            }
            self::$smart_tpl->left_delimiter  = '<{';
            self::$smart_tpl->right_delimiter = '}>';
        }
        
        return self::$smart_tpl;
    }

require_once('./php/include/common.php');
require_once(WEB_PHP . '/starton.php');

$tpl = app::get_tpl();
$tpl->assign('meta_keywords',APP_KEYWORDS);
$tpl->assign('meta_author',APP_AUTHOR);
$tpl->assign('meta_desc',APP_DESC);
$tpl->assign('web_templetdir',WEB_Tpl_Path);
$tpl->assign('title',APP_TITLE);
$tpl->assign('web_code',WEB_CODE);
$tpl->display('index.html');


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<{$web_code}>">
<meta name="keywords" content="<{$meta_keywords}>">
<meta name="author" content="<{$meta_author}>">
<meta name="description" content="<{$meta_desc}>">
<title><{$title}></title>
<link href="./css/index.css" rel="stylesheet" type="text/css" />
<script src="<{$web_templates}>/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
    alert('ok');
    $("p").css("color","red");
});
</script>
</head>
<body>
<p>ssss</p>
</body>
</html>

发现jquery.js没有引入成功。经过一点一点测试发现web_templates是路径c:/php/..../jquery.js 无效。

必须是url的方式如

http://localhost:6060/chshsl/templets/js/jquery.js


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值