Xuups
Get an account!     Login

Utilities

Main menu

Who's Online

15 user(s) are online (1 user(s) are browsing Hacks and Tips)

Members: 0
Guests: 15

more...

Get Xoops

Support Xuups Project

Themes :  How to sucessfuly add scripts in your Xoops Themes
Tags: themes   tips  
 
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:
<!-- RMVadded 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(nulltrue) . $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(nulltrue) . $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!


TDM

Author
trabis
Author trabis
News by the same authorMore stories
Author rssAuthor rss
StatisticsStatistics
 
Story
Date 2010/7/25 15:23:01
Views 13218
Favorites 0
Send this Story to a FriendSend
Printer Friendly PagePrint
Create a PDF from the articleCreate a pdf
 
Bookmarks
         
         
         
         
         
     
Recents
How to sucessfuly add scripts in your Xoops Themes
Query timers on debug for xoops 2.3
Highlighting current module on mainMenu
Main menu hack - on click submenus
Preventing empty blocks to display
Random
How to sucessfuly add scripts in your Xoops Themes
Query timers on debug for xoops 2.3
Main menu hack - on click submenus
Preventing empty blocks to display
Hacking Multimenu - Selected menus
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
 

Login

Username:

Password:

Remember me



Lost Password?

Register now!

Ajax Search


Advanced Search

Sub menu

Last comments