Fork me on GitHub
Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules
New Posts New Topics All Posts All Forums Index General Modules Themes Development International XOOPS.org

Search

Donat-O-Meter

Make donations with PayPal!
Stats
Goal: $100.00
Due Date: Sep 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00

Learn XOOPS Core

Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

- 2 2.5 2.6 3.0 4 6 2013 adslight Android AntiHarvesting AntiMalUser AntiSpam API Apple Battlefield billige Bootstrap Captcha cell chronolabs CHUNG Clicks content CĂN demo docek download Dresses evden eve facebook Fat floor Food for free Gateway Google Guide herre Home Honeypot HP Human HỘ IP iPhone jQuery Language List log Loss mobile module modules Monster new newbb news NHÀ online PARK phone PHP Prevention profile project Protector publisher Rapid RESIDENCE responsive review Rights rmcommon security Sentry site Smartphone Smoking Solution Spam stem Studio tags tdmcreate template The Theme themes web weight Wishcraft xoops Xortify XPayment ZendFramework

New Users

Registering user

# 137767

obdvip

Welcome to XOOPS!




Bottom   Previous Topic   Next Topic  Register To Post



#1 Posted on: 2010/7/24 16:47 How to correctly add scripts in your XOOPS theme
If you want to add scripts or stylesheets in your theme do not hardcoded them in the header.

Hardcoding it will probably cause duplication if some other module include the same file.

The solution is using Xoops API that already handles duplicate files.

So instead of just using <{$xoops_module_header}> ,you need to do the following:
<!-- RMVadded module header -->
  <{
php}>
    global 
$xoTheme;
    
$xoTheme->addScript('http://yoursite.com/somescript.js');
    
$xoTheme->addStyleSheet('http://yoursite.com/somesstyle.css');
    
$this->assign('xoops_module_header'$xoTheme->renderMetas(nulltrue));
  <{/
php}>
  <{
$xoops_module_header}>


Have fun!


Top


Xoops User Utilities | Xoops Search Engine | vil3/trabisdementia
trabis
Core Developer
Core Developer
Joined:
2006/9/1 13:10
From Portugal
Group:
Webmaster
Registered Users
Posts: 2198
(Show More) (Show Less)


#2 Posted on: 2010/7/24 17:02 Re: How to correctly add scripts in your XOOPS theme
You don't need the full url there, just

Quote:

$xoTheme->addScript('somescript.js');


$xoTheme will add the url automatically for you. :)

Top

Catzwolf
Home away from home
Home away from home
Joined:
2007/9/29 23:21
Group:
Registered Users
Posts: 1317
(Show More) (Show Less)


#3 Posted on: 2010/7/25 12:53 Re: How to correctly add scripts in your XOOPS theme
There is some code missing for legacy support.
Better solution can be found here:
http://www.xuups.com/modules/mynews/article.php?storyid=17

Top


Xoops User Utilities | Xoops Search Engine | vil3/trabisdementia
trabis
Core Developer
Core Developer
Joined:
2006/9/1 13:10
From Portugal
Group:
Webmaster
Registered Users
Posts: 2198
(Show More) (Show Less)


#4 Posted on: 2010/7/25 13:50 Re: How to correctly add scripts in your XOOPS theme
I fear this will lead to more problem in the long run.

I really do not understand this approach when this should have been handled by the template class? Really, xoTheme should check whether or not the file has been added before and take the required steps to prevent compatibility issue.

Instead we create another file and class to do this and thus instead of making the process simple we begin to complicate the issue further.

Doing this is simple:
$xoTheme->addScript('somescript.js');

Doing this begins to create problems:

$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');

Why? Because we could have easily did a check to see whether the javascript was 'JQuery.js' and used the correct version from xoTheme or template class and this way compatibility wouldn't have been affected in the short or long run.

Or better still:

$xoTheme->addJQuery();
$xoTheme->addJQueryUI();

Again we complicate things when there is no need to.


Top

Catzwolf
Home away from home
Home away from home
Joined:
2007/9/29 23:21
Group:
Registered Users
Posts: 1317
(Show More) (Show Less)







You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You can vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.

[Advanced Search]