XOOPS 許多佈景檔會預先在入 JS
在模組內如果重複引用到 JS 檔的話,容易造成Javascript 的程式出錯
提供一個函式
function tpl_file_include($tpl_include){
if(!isset($xoopsTpl)){ $xoopsTpl = new XoopsTpl(); }
$xoopsTheme = $xoopsTpl->fetch($GLOBALS['xoTheme']->path . '/' . $GLOBALS['xoTheme']->canvasTemplate);
foreach($tpl_include as $type => $file_array){
foreach($file_array as $file){
if(is_bool(strpos($xoopsTheme, $file))){
switch($type){
case 'js':
$GLOBALS['xoTheme']->addScript(XOOPS_URL.'/browse.php?Frameworks/' . $file);
break;
case 'css':
$GLOBALS['xoTheme']->addStylesheet( XOOPS_URL.$file );
break;
}
}
}
}
}
此函式的作用在於驗證佈景檔是否有載入相同的字串檔案
使用陣列將檔案引入
陣列 必須放在 header.php 下方
以下為範例:
來個簡易範例(後台):
include 'header.php';
include '../include/function.php';
include_once XOOPS_ROOT_PATH . '/include/cp_header.php';
include_once XOOPS_ROOT_PATH . '/include/cp_functions.php';
$tpl_include['js'] = array('jquery/jquery.js','jquery/plugins/jquery-ui.js');
xoops_cp_header();
tpl_file_include($tpl_include);
xoops_cp_footer();
前台:
include_once '../../mainfile.php';
include_once 'include/function.php';
$tpl_include['js'] = array('jquery/jquery.js','jquery/plugins/jquery-ui.js');
include_once XOOPS_ROOT_PATH.'/header.php';
tpl_file_include($tpl_include);
include_once XOOPS_ROOT_PATH.'/footer.php';
文章發布於:http://mesak.wablog.info/blog/read.php?450
|