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


你可能感兴趣的:(php Smarty模版引擎中引入javascript源文件)