If you want to add scripts or style sheets in your theme.html do not hardcode them in the header.
Hardcoding will probably cause duplication if some other module includes the same files.
The solution is using Xoops API that already handles duplicated files!
So, instead of just using <{$xoops_module_header}>, you will need to do the following:
<!-- RMV: added module header -->
<{php}>
global $xoTheme;
$xoTheme->addScript('somescript.js');
$xoTheme->addStyleSheet('somesstyle.css');
$header = empty($GLOBALS['xoopsOption']['xoops_module_header']) ? $this->get_template_vars('xoops_module_header') : $GLOBALS['xoopsOption']['xoops_module_header'];
$this->assign('xoops_module_header', $xoTheme->renderMetas(null, true) . $header);
<{/php}>
<{$xoops_module_header}>
A practical example would be the inclusion of the jquery library provided by the core. To avoid jquery to be loaded multiple times you should use this code:
<{php}>
global $xoTheme;
$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
$header = empty($GLOBALS['xoopsOption']['xoops_module_header']) ? $this->get_template_vars('xoops_module_header') : $GLOBALS['xoopsOption']['xoops_module_header'];
$this->assign('xoops_module_header', $xoTheme->renderMetas(null, true) . $header);
<{$xoops_module_header}>
<{/php}>
So, what is this code doing?
When theme is being rendered, the smarty variables are already assigned. This means that $xoops_module_header is already populated with the scripts that the modules have requested. To add a new script and make sure it is not already requested, we need to get our instance of $xoTheme, add our script, and reassign $xoops_module_header by calling $xoTheme->renderMetas().
If you need to add scripts from module templates, it is a little more easy:
<{php}>
global $xoTheme;
$xoTheme->addStyleSheet('somestylesheet.css');
<{/php}>
Viva Xoops! |